A couple of quick'n'dirty ways - based on your grep
approach:
find . -print0 | grep -Fzf client.txt
or
shopt -s globstar
printf '%s\0' **/* | grep -Fzf client.txt
Both will be safe for any legal filenames, and give a null-delimited list of paths that you can pass to another program. Note that both will match entries from client.txt
anywhere in the path - which may not be what you want.
A more sophisticated way, assembling a list of -name
arguments for find
using a shell array:
while IFS= read -r client; do namearr+=(-name "$client" -o); done < client.txt
find . \( "${namearr[@]}" -false \) -print
Change -print
to -print0
to get null-delimited results like the other methods. Note that this matches exact filenames. You could change -name "$client"
to -name "*$client*"
to get wildcard matching within the filename (or to -path "*$client*"
to get matching anywhere in the path, similar to the grep
-based solutions).