I want to run a command on a directory to print out all files in that directory, then grep all files recursively for those found file names, basically to check and see if X file is used in any PHP or HTML files in a directory. If X file is found to NOT be in any files, print it’s name.
I have this so far, I can’t figure out how to pass to grep what I have then print those without results.
find . -path ./images -prune -o -name '*' -type f -print | sed 's!.*/!!'
I could use exec as so:
find . -path ./images -prune -o -name '*' -type f -exec grep -R '{}' ./* \;
But then I can’t sed away the ./dir/etc/ from in front of the file names that find gives me.
The other part of the query that is perplexing me is I can’t figure out how to get grep or find to print those without results in grep.
I think something like this might help:
In this example,
-printf "%f\n"causesfindto return only the file name without the path. The result is a file used as the search patterns for grep and is passed as input onstdinusing-f -. The-Rtells grep to search recursively (which you already know). The--colormakes things look nice.To list only the matching file names use
grep -l -R -f - .. Then to find the files without results, you will have to find the files that are not in that list.This post might help you with that.