AIX find ignore directory

I am using aix. I would like to ignore the /u directory. I tried this but it is not working.

find / -type f -type d \( -path /u \) -prune -o -name '*rpm*' 2>/dev/null
/u/appx/ls.rpm
/u/arch/vim.rpm

You don't want to match on -type d before the prune as the true condition negates the prune

I'd go with:

find / -path /u -prune -type f -o -name '*rpm*'
1 Like

Doesn't it make more sense to have the -type f right from the -o ?
Also, if -prune is true then it is printed, unless there is an action like -print or -exec on the other branch.

find / -path /u -prune -o -type f -name '*rpm*' -print
1 Like

What about if you are trying to ignore multiple directories? I was trying to follow this example. I want to search for "*rpm*" in addition to what this example has.

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

linux - How to exclude a directory in find . command - Stack Overflow

Straight forward:

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -name '*rpm*' -print

Note that the default is -a locigal AND and has higher precedence than -o logical OR. So you can say as well

find . \( -type d -a \( -path dir1 -o -path dir2 -o -path dir3 \) -a -prune \) -o \( -name '*rpm*' -a -print \)

If the left side of a -a is true it must evaluate the right side, and vice versa.
If the left side of a -o is false it must evaluate the right side, and vice versa.

Regarding the -path , its argument must match the whole pathname. If the start directory is a . then it must begin with ./

1 Like