The whole concept behind find
is that it provides advanced options for locating files. There should rarely be any need to parse the output with grep
or another tool.
Here are a couple of good links about using find:
As mentioned before, it would help if you detailed your requirements more thoroughly, but I imagine something like this would work:
find . -type d -path '*/log*' -print
option lets you match the entire path of the file, not just the name. The slash in the globbing pattern ensures that only directory names that start
" are printed. Finally, it's usually advisable to get in the habit of explicitly adding the -print
action, even though it is the default action if nothing is given. There are some advanced search cases where it's needed. See the last section of the first link.
Edit: After reading more closely, it looks like you want to match paths that have two
instances of "log
" in them? In that case, just double the globbing pattern to:
find . -type d -path '*/log*/log*' -print
Finally, if you are going to use this list in a loop or similar command, be sure to use the -print0