<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Move file but keep directory tree in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636331#M105045</link>
    <description>Lets's try this way out,&lt;BR /&gt;&lt;BR /&gt;for filename in `find / -name \*.gz`;&lt;BR /&gt;do&lt;BR /&gt;newdir=dirname $filename&lt;BR /&gt;mkdir -p /var/tmp/$newdir&lt;BR /&gt;mv $filename /var/tmp/$newdir&lt;BR /&gt;done</description>
    <pubDate>Wed, 28 Sep 2005 00:10:54 GMT</pubDate>
    <dc:creator>Vibhor Kumar Agarwal</dc:creator>
    <dc:date>2005-09-28T00:10:54Z</dc:date>
    <item>
      <title>Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636324#M105038</link>
      <description>I am writing a script that searches for files with specific extensions and moves them to another directory.&lt;BR /&gt;&lt;BR /&gt;I'd like to be able to keep the directory tree of the file when the file is in it's new location.&lt;BR /&gt;&lt;BR /&gt;Example: I'd like to move the file stuff.gz from /home/jerry to /var/tmp/home/jerry.&lt;BR /&gt;&lt;BR /&gt;Any suggestions on how to do this within the structure of my already written script?&lt;BR /&gt;&lt;BR /&gt;(Main part of my script is below)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;find / -name \*.gz &amp;gt;$OUTPUT&lt;BR /&gt;&lt;BR /&gt;for i in $(&amp;lt;$OUTPUT)&lt;BR /&gt;do&lt;BR /&gt;    {insert command here}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for any suggestions you may have.&lt;BR /&gt;Mike&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Sep 2005 14:39:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636324#M105038</guid>
      <dc:creator>Mike Ehrman</dc:creator>
      <dc:date>2005-09-27T14:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636325#M105039</link>
      <description>I would do a cp -rp and then remove the source file. The cp -rp would create the necessary directory structure and keep the same file protection as the source file.  So the script would look like;&lt;BR /&gt;&lt;BR /&gt;find / -name \*.gz &amp;gt;$OUTPUT&lt;BR /&gt;&lt;BR /&gt;for i in $(&amp;lt;$OUTPUT)&lt;BR /&gt;do&lt;BR /&gt;cp -rp $i /var/tmp/$i&lt;BR /&gt;rm $1&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Sep 2005 14:45:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636325#M105039</guid>
      <dc:creator>Alan Meyer_4</dc:creator>
      <dc:date>2005-09-27T14:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636326#M105040</link>
      <description>Easy:&lt;BR /&gt;&lt;BR /&gt;find /home/jerry -name '*.gz' | cpio -pudvm /var/tmp</description>
      <pubDate>Tue, 27 Sep 2005 14:46:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636326#M105040</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-09-27T14:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636327#M105041</link>
      <description>The cpio passthru option as listed by Clay.&lt;BR /&gt;As the root user;&lt;BR /&gt;&lt;BR /&gt;# cd /home/jerry&lt;BR /&gt;# find . -depth | cpio -pmuldv /var/tmp/&lt;BR /&gt;&lt;BR /&gt;This will keep perms and owners as well.</description>
      <pubDate>Tue, 27 Sep 2005 15:16:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636327#M105041</guid>
      <dc:creator>Rick Garland</dc:creator>
      <dc:date>2005-09-27T15:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636328#M105042</link>
      <description>Thank you Alan, Clay and Rick.&lt;BR /&gt;&lt;BR /&gt;Alan - the cp command with the rp options did not create the directory structure on my HP-UX 11i box.  The man page says p is for keeping permissions.&lt;BR /&gt;&lt;BR /&gt;Clay &amp;amp; Rick - the cpio command works.&lt;BR /&gt;&lt;BR /&gt;Here is how I incorporated it into my scripts...&lt;BR /&gt;&lt;BR /&gt;find / -name \*.gz &amp;gt;$OUTPUT&lt;BR /&gt;&lt;BR /&gt;cat $OUTPUT | cpio -dumpv /var/tmp&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If anyone has a better way to incorporate it into my script I'd love to hear it.&lt;BR /&gt;&lt;BR /&gt;Mike&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Sep 2005 15:28:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636328#M105042</guid>
      <dc:creator>Mike Ehrman</dc:creator>
      <dc:date>2005-09-27T15:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636329#M105043</link>
      <description>Not exactly sure what you are looking for but give it try:&lt;BR /&gt;&lt;BR /&gt;Instead of the 2 lines you have, just have the single line as listed previously posted.&lt;BR /&gt;&lt;BR /&gt;find /home/jerry -name '*.gz' | cpio -pmuldv /var/tmp&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You can have just the 1 line doing the copies.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Sep 2005 15:59:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636329#M105043</guid>
      <dc:creator>Rick Garland</dc:creator>
      <dc:date>2005-09-27T15:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636330#M105044</link>
      <description>Hmm it's the -r that's suppose to create the subtrees though...  In anycase, what's important is that you got it solved...  :)</description>
      <pubDate>Tue, 27 Sep 2005 16:43:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636330#M105044</guid>
      <dc:creator>Alan Meyer_4</dc:creator>
      <dc:date>2005-09-27T16:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636331#M105045</link>
      <description>Lets's try this way out,&lt;BR /&gt;&lt;BR /&gt;for filename in `find / -name \*.gz`;&lt;BR /&gt;do&lt;BR /&gt;newdir=dirname $filename&lt;BR /&gt;mkdir -p /var/tmp/$newdir&lt;BR /&gt;mv $filename /var/tmp/$newdir&lt;BR /&gt;done</description>
      <pubDate>Wed, 28 Sep 2005 00:10:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636331#M105045</guid>
      <dc:creator>Vibhor Kumar Agarwal</dc:creator>
      <dc:date>2005-09-28T00:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636332#M105046</link>
      <description>Put your $OUTPUT in a loop and pass through it, It would be efficient and good way of doing.&lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Wed, 28 Sep 2005 00:28:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636332#M105046</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2005-09-28T00:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Move file but keep directory tree</title>
      <link>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636333#M105047</link>
      <description>You can do it simply as,&lt;BR /&gt;&lt;BR /&gt;# find / -name "*.gz" | awk '{ print "cp -R "$0" /var/tmp" }' | ksh&lt;BR /&gt;&lt;BR /&gt;It will copy directory sturcture to /var/tmp. You can change location also with awk statement.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Wed, 28 Sep 2005 00:41:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/move-file-but-keep-directory-tree/m-p/3636333#M105047</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-09-28T00:41:43Z</dc:date>
    </item>
  </channel>
</rss>

