Search from a *.txt and copy files to new directory

148 Views Asked by At

I have a *.txt file with lines of file names, over 500 of them. No paths are includes, just the file names. I want to point to a directory on a server that has subdirectories with files in it, search the *.txt file for the file names and copy anything it finds to a new directory (no need for subdirectories here).

Having a hard time finding anything that works. Tried xargs and rsync --files-from but so far no luck.

1

There are 1 best solutions below

3
Uprooted On
find directory/on/server/ -type f |
while read f
do
    if fgrep -q "$(basename "$f")" '*.txt'; then
        cp "$f" new/directory/
    fi
done