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'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
1  
@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
1  
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
1  
@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
1  
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
3  
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

 
discard

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

Browse other questions tagged or ask your own question.