Say I have a list of keywords:
$ cat filenames.txt
satin
perdido
savoy
stockings
april
lullabye
I want to find all the files in some directory that contains those keywords.
I have tried something like:
find some_dir/ -type f "$(printf '-or -iname *%s* ' $(cat filenames.txt))"
But somehow I am not able to use printf to build the whole find command; I get:
-bash: printf: -o: invalid option
The
find
command does not search the files' content.The
-iname
option selects the filenames.The error means that
printf
does not reconize the-o
option. In such situation you should useprintf -- '-o...
I think the final filter you are looking for is:
Note the
\( ... \)
to enclose all the-iname ...
-o ...
is said to be POSIX in theman find
You need to be sure that the
filenames.txt
file contains at least one value.If you need to find the filenames in the
some_dir/
, then give a try to this: