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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
This works for me:
find . ! -path "./.git*" -a ! -name states_to_csv.pl
so converting to your should be something like
find /etc /srv ! -path "./srv/tftp/pxelinux.cfg*" -a ! -name /etc/mtab
The -a flag stand for “and”.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0