You are not logged in.

#1 2008-10-15 14:21:46

jnwebb
Member
Registered: 2008-07-07
Posts: 52

Bash find and move files help

I am trying to locate all files with *.ars is all subfolders of a directory and move the a folder

I have tried:

mv `find . -name "*.ars"` SASSI5

but I get the following errors

mv: rename ./EAST/ROCK/EUS to SASSI5/EUS: No such file or directory
mv: rename ROCK to SASSI5/ROCK: No such file or directory
mv: rename M5.5 to SASSI5/M5.5: No such file or directory
mv: rename 0-50/A-GRV330.CTH.F/A-GRV330.CTH.F-139.ars to SASSI5/A-GRV330.CTH.F-139.ars: No such file or directory

it seems to be trying to recreate the subdirectories that the files were in in my new folder.

Any help...I am sure this is simple

Thanks

Offline

#2 2008-10-15 14:35:04

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Bash find and move files help

You can see what mv thinks of the files it has to move: they don't end in .ars (except the last one) So there are spaces in the filename.

Try it with IFS set to newline.

IFS="
"
mv `find . -name "*.ars"` SASSI5

If it still doesn't work then use the -exec switch of find and something like mv '{}' SASSI5 \;

Offline

#3 2008-10-15 14:39:31

tuxce
Member
Registered: 2008-02-19
Posts: 56
Website

Re: Bash find and move files help

or

find . -name "*.ars" -exec mv "{}" absolute_path_destination \;"

Offline

#4 2008-10-16 14:32:28

jnwebb
Member
Registered: 2008-07-07
Posts: 52

Re: Bash find and move files help

Thanks.

Another question.  I  hundreds of files with the extension "smooth".  They are all located in several different subfolders (139.P, 151.P, 158.P).  Of each subfolder, there are several of those...so I have say 10 139.P folders, 10 151.P folders, etc.

I would like to take all of the "smooth" files from all of the 139.P folders and place them in one folder.

Offline

#5 2008-10-16 15:15:44

jnwebb
Member
Registered: 2008-07-07
Posts: 52

Re: Bash find and move files help

Or maybe more easily...if I dump all of the filenames w/ extentsions into a file:

./WEST/ROCK/WUS ROCK M6.5 100-200/158.P/SMOOTHED/SOD015-5.RSsmooth
./WEST/ROCK/WUS ROCK M6.5 100-200/158.P/SMOOTHED/SON033-5.RSsmooth
./WEST/ROCK/WUS ROCK M6.5 100-200/158.P/SMOOTHED/SOR315-5.RSsmooth
./WEST/ROCK/WUS ROCK M6.5 50-100/139.P/SMOOTHED/A-CSH090-5.RSsmooth
./WEST/ROCK/WUS ROCK M6.5 50-100/139.P/SMOOTHED/A-MAL270-5.RSsmooth
./WEST/ROCK/WUS ROCK M6.5 50-100/139.P/SMOOTHED/A-ORR090-5.RSsmooth
./WEST/ROCK/WUS ROCK M6.5 50-100/139.P/SMOOTHED/A-RIV270-5.RSsmooth
./WEST/ROCK/WUS ROCK M6.5 50-100/139.P/SMOOTHED/AMB--X-5.RSsmooth

etc...

How can I then move all files w/ 139.P into a separate file..I can then copy and move the files with this list.

Offline

#6 2008-10-16 15:43:44

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Bash find and move files help

Your suggestion in post #5 is not needed.

You can match the entire filename with -path instead of -name.

find . -path '*/139.P/*smooth' -exec mv "{}" destination \;

Offline

#7 2008-10-16 19:02:58

jnwebb
Member
Registered: 2008-07-07
Posts: 52

Re: Bash find and move files help

Thanks that helps!!!

Offline

Board footer

Powered by FluxBB