Solaris equivalent for depth/prune

findsolaris

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

Best 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
Related Question