Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'm trying to find files from a list and copy them to another place. So I started my test loop like that:

# cat ~/my_filelist.txt | while read file ; do echo "$file" ; done

After I hit enter all filenames from my_filelist.txt are print to stdout, fine.

Now I replaced "echo" with "find" command like that:

# cat ~/my_filelist.txt | while read file ; do find . -name "$file" ; done 

I thought that find will print the results to stdout, but nothing happens O_o

I can see that find is working but where is the ouput?

Could somebody tell me what I'm doing wrong?

Many thanks in advance!

share|improve this question
@TheSAS The first argument to find is always the directory for find to walk. Besides, arguments are (almost) never interpreted by the shell as program names. echo rm -rf / will print rm -rf /, not delete everything. – Blacklight Shining Oct 30 '13 at 13:55
Are the filenames in my_filelist.txt absolute or relative to .? They have to be basenames, without paths; -name only looks at the basename of each file it encounters. If you want to use paths, use -path instead. – Blacklight Shining Oct 30 '13 at 13:58
@TheSAS find . -name foo works perfectly fine for me on both Debian (GNU find 4.4.2) and on Mavericks (can't tell what version of find this is). – Blacklight Shining Oct 30 '13 at 14:05
now tried this cat ~/my_filelist.txt | while read file ; do find . -name "$file" -exec cp{} /my/destination/folder \; done and it ends up with > like something is missen – gonzo Oct 30 '13 at 14:18
You need a semicolon after the find. The escaped semicolon lets find know that that's the end of the -exec part, then you need another semicolon before the done to mark the end of the find invocation for the shell: cat ~/my_filelist.txt | while read file ; do find . -name "$file" -exec cp {} $destination_dir \; ; done; – Blacklight Shining Oct 30 '13 at 14:30

Your Answer


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

Browse other questions tagged or ask your own question.