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:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html
As mentioned before, it would help if you detailed your requirements more thoroughly, but I imagine something like this would work:
Code:
find . -type d -path '*/log*' -print
The
-path 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 with "
log" 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:
Code:
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 option instead.
http://mywiki.wooledge.org/BashFAQ/020