Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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

Your Answer


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.