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!
.beetween find and -name?.is a substitute for asource. Try to use./or~/or/. – TheSAS Oct 30 '13 at 13:50findis always the directory forfindto walk. Besides, arguments are (almost) never interpreted by the shell as program names.echo rm -rf /will printrm -rf /, not delete everything. – Blacklight Shining Oct 30 '13 at 13:55my_filelist.txtabsolute or relative to.? They have to be basenames, without paths;-nameonly looks at the basename of each file it encounters. If you want to use paths, use-pathinstead. – Blacklight Shining Oct 30 '13 at 13:58.is not a correct directory. Try tofind . -name foo- error: paths must precede expression. – TheSAS Oct 30 '13 at 14:02find . -name fooworks perfectly fine for me on both Debian (GNUfind 4.4.2) and on Mavericks (can't tell what version offindthis is). – Blacklight Shining Oct 30 '13 at 14:05cat ~/my_filelist.txt | while read file ; do find . -name "$file" -exec cp{} /my/destination/folder \; doneand it ends up with>like something is missen – gonzo Oct 30 '13 at 14:18find. The escaped semicolon letsfindknow that that's the end of the-execpart, then you need another semicolon before thedoneto mark the end of thefindinvocation 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:30cp{}. In htop I can seefindworkingfind . -name 152_TU_2011-05-09.TIF ? -exec cp{} /mnt/share/corrupt ;. But no files are copied :( – gonzo Oct 30 '13 at 14:57