Maxdepth option of find command not working

Can you please figure out what is the issue here

$ find . -maxdepth  1 -type f -size 0 -print
find: bad option -maxdepth

please find the OS details

$ uname -a
HP-UX g5u1216 B.11.31 U ia64 2614088426 unlimited-user license

maxdepth is a GNU-ism, try -depth instead.

As far as I can tell POSIX compliance for find does not support -maxdepth or -mindepth as arguments to the find command.

find

The find -depth primary produces a post-order walk of the file hierarchy instead of the default pre-order walk; it has no effect on how deep find goes as it walks the hierarchy. To get what TomG requested, just using standard find primaries, try:

find . \( -type d ! -name . -prune \) -o \( -type f -size 0 -print \)

or if the name of the directory being searched was specified by a variable:

find "$dir" \( -type d ! -name "$dir" -prune \) -o \( -type f -size 0 -print \)
1 Like

You can skip -type d before the ! -name . -prune .
(And then it becomes clear you don't need the brackets.)
Just seeing you must switch the order, too:

find . -type f -size 0 -print -o ! -name . -prune

Hi Don,

Can you please tell me why -o is used. I am confused,because both conditions in the brackets have to be satisfied right. So can we use an 'and' condition.

Thank You

From the (Linux) man page:

1 Like

I have a general pattern that I remember that works for lots of cases. Your problem is simpler than many and in this specific case, I should have given you the much simpler command:

find . ! -name . -prune -type f -size 0

or:

find "$dir" ! -name "$dir" -prune -type f -size 0
1 Like