linux find on multiple patterns
bash, linux
Solution
This solution calls `find` and `fgrep` only once:
find . | fgrep -f my_file > outputfile
I assume that `my_file` has a list of files you are looking for, with each name on a separate line.
Explanation
- The `find` command finds all the files (including directories) in the current directory. Its output is a list of files/directories, one per line
- The `fgrep` command search from the output of the find command, but instead of specifying the search term on the command line, it gets the search terms from `my_file`--that's what the `-f` flag for.
- The output of the fgrep command, which is the list of files you are looking for, are redirected into `outputfile`
Problem
I need to do a find on roughly 1500 file names and was wondering if there is a way to execute simultaneous find commands at the same time. Right now I do something like ``` for fil in $(cat my_file) do find . -name $fil >> outputfile done ``` is there a way to spawn multiple instances of find to speed up the process. Right now it takes about 7 hours to run this loop one file at a time.