Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to find some files inside a directory. By default, the find command is searching the directory which I have specified and it's sub directories.

I tried to use depth/maxdepth and prune, but nothing helped to overcome this. Can somebody point out the right way to use depth/prune in Solaris?

My code looks like this:

find file_path -depth 1 -name '*.log'

I am getting the following error:

find: bad option 1
find: [-H | -L] path-list predicate-list
share|improve this question
add comment

migrated from stackoverflow.com Aug 8 '11 at 11:17

This question came from our site for professional and enthusiast programmers.

1 Answer

You're confusing two unrelated options that have vaguely similar names:

  • -depth doesn't take any argument. If present, it tells find to process the contents of a directory before processing the directory itself.
  • -maxdepth N (where N is an integer) limits the recursion to N levels of subdirectories.

The -maxdepth option is an extension found in some versions of find, but not Solaris's. There's a trick to using only standard options to find to process a directory without recursing: use -prune on subdirectories, but exclude the toplevel directory. Since the only way to match the toplevel directory is by name, arrange for the name to be . (which will never be the name of a subdirectory).

find /directory/to/traverse/. -name . -o \
                              -type d -prune -o \
                              -name '*.log' -print
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.