bash script to copy found directory and parent to another drive,
M. Fioretti
mfioretti at nexaima.net
Sun Sep 14 09:32:51 UTC 2008
On Sat, Sep 13, 2008 23:44:39 PM -0400, Lance Hoffmeyer wrote:
> Hey all,
>
> I want to... find
>
> /media/music/jazz/coltrane/ROIO
> /media/music/jazz/Davis/ROIO
> /media/music/rock/LedZep/ROIO
>
> and copy them to
>
> /media/flash/jazz/coltrane/ROIO
> /media/flash/jazz/Davis/ROIO
> /media/flash/rock/LedZep/ROIO
here is some rough code you'll have to clean and tweak to your needs,
surely there are other ways to do the same:
cd /media/music
find . -name ROIO > /tmp/list_of_files_to_copy
tar cf /tmp/files_to_copy.tar -T /tmp/list_of_files_to_copy
cd /media/flash
tar xf /tmp/files_to_copy.tar
in other words, write all "ROIO" files, path included, to
/tmp/list_of_files_to_copy, which will look like:
jazz/coltrane/ROIO
jazz/Davis/ROIO
rock/LedZep/ROIO
then create a tar file, containing all and only the files listed in
/tmp/list_of_files_to_copy, move to /media/flash and "unpack" the tar
file inside the new directory.
again, this is a sketch. You have to tweak the code above to make it
robust (I have no time and would need more details anyway). Possible
caveats:
if you have no extra disk space to create /tmp/files_to_copy.tar,
there may be some tar option to tar/compress on the fly
the code as written _may_ not work on file names with spaces or weird
non-ascii characters (not sure and don't remember, study the options
in the man pages of tar and find)
Ciao,
Marco
--
Your own civil rights and the quality of your life heavily depend on how
software is used *around* you: http://digifreedom.net/node/84
More information about the ubuntu-users
mailing list