Since you're not doing a recursive search, there's no need to use find
, unless you wanted to include only directories and not symbolic links to directories. Assuming there are no directories whose name begins with a dot (if there are, use for x in .*/ */; do …
), the following will search the names of all directories and symbolic links to directories in the current directory:
for x in */; do grep -F "GET /${x%/}" /var/log/apache2/blah.com; done
If you were doing a recursive search, you could avoid a leading dot by searching from *
rather than .
(same remark as above regarding names beginning with a dot).
find * -type d -exec grep -F "GET /${x%/}" /var/log/apache2/blah.com
Another possibility is to postprocess the output of find
. This is especially useful in combination with grep's ability to search multiple newline-separated patterns.
grep -F "$(find . -type d | sed -e 's!^\.!GET !')" /var/log/apache2/blah.com
Note that in all cases you're assuming there aren't any characters in the directory names that would be escaped in the Apache log. This is solvable with a little further postprocessing of the find
output.