I need to search a large directory tree for a large number of possible file names, i.e. I have an input file with a long list of strings that I need to find in the tree (or as below: print all those that are not in the tree)
As a file system based solution I can do something like this:
while read a; do count=`find /path/to/dir -name "*$a*" | wc -l`; ; if [ $count -eq 0 ]; then echo $a; fi done < inputnames.txt
which is wildly inefficient given the size of the tree and the size of the input file. I then figured I could simply dump the output of
find into a file
find /path/to/dir > pathtodir_tree.txt
and then grep the file.
while read a; do count=`grep $a pathtodir_tree.txt | wc -l`; if [ $count -eq 0 ]; then echo $a; fi done < inputnames.txt
which is much faster. My questions are: am I missing a more efficient file system based solution? If not, is there another solution that is more efficient (or generally better) than the grep based solution I am proposing?