Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to copy all *.tif files from ./old to the ./new. In ./old i have lots of subdirs with different files, and in ./new i need only TIF files, without folder tree. So, I had tried cp -vR ./old/*.TIF ./new and got an error:

No such file file or dirrectory "./old/*.TIF"

What I'm doing wrong?

share|improve this question

migrated from stackoverflow.com Dec 22 '12 at 19:22

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

up vote 4 down vote accepted

Use find for this find . -name "*.TIF" -exec cp {} new \;

So find is used to find files. The command is saying find files starting from here . where the name of the file -name ends in .tif remember the double quotes for shell expansion. So to find all the tif files is simply.

find . -name "*.tif"
./2/3/3.tif
./2/2.tif
./1.tif

We then use -exec to do something with files in this case cp found files {} to the target directory new followed by an escaped semicolon \;

share|improve this answer
1  
Thanks! thats exactly what i need. –  Sergii Rechmp Nov 2 '12 at 10:12
add comment

in old directory (direct) you might not be having any .tif files.

moreover you can get a list of files and copy them using a simple script

find /old -type f | xargs grep *.tif will give you the list

you can do like

for i in `find /old -type f | xargs grep *.tif` 
do
cp $i /new
done;
share|improve this answer
add comment

It should be like this. You have to enter old directory:

cd old
cp -R *.tif ../new
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.