Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Dec 22 '12 at 19:22

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

up vote 7 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"

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
Thanks! thats exactly what i need. – Sergii Rechmp Nov 2 '12 at 10:12

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

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

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` 
cp $i /new
share|improve this answer

You must log in to answer this question.