Andrew Hall Andrew Hall - 6 months ago 17
Bash Question

bash shell: recursively search folder and subfolders for files from list

Until now when I want to gather files from a list I have been using a list that contains full paths and using:

cat pathlist.txt | xargs -I % cp % folder


However, I would like be able to recursively search through a folder and it's subfolders and copy all files that are in a plain text list of just filenames (not full paths).

How would I go about doing this?

Thanks!

Answer

Try something like

find folder_to_search -type f | grep -f pattern_file | xargs -I % cp % folder
Comments