Bash Find Command – Combining -path and -prune to Exclude Files and Directories

bashfind

I have a directory /srv/tftp/pxelinux.cfg and a file /etc/mtab. I want to exclude both from find. But whatever I do, either one always is not excluded

find /etc /srv -path /srv/tftp/pxelinux.cfg -prune -o \! -path /etc/mtab
find /etc /srv \( -path /srv/tftp/pxelinux.cfg -prune -o -print \) -a \( \! -path /etc/mtab \)

Note: I find the -path /foo -prune -o -print syntax highly confusing and unintuitive

Best Answer

Try this variant:

$ find /etc /srv \( -path /srv/tftp/pxelinux.cfg -o -path /etc/mtab \) \
    -prune -o -print

This will "prune" either of those 2 -path arguments from the list, and print everything else.

Related Question