I have a directory whose contents should never be found by find, so I aliased find like this:

alias find='find -not -path "*.sync*"'

the issue is that find now complains that operators are not positional whenever I use something like find -depth. Is there another way to do this cleanly?

  • Perhaps something with ! -regex?
    – Peschke
    Jul 14 '18 at 17:12

An operator named -not does not exist in find. did you mean !? -path is an extension found on many find implementations but not in all.

Your main problem may be that all path name arguments must appear first on the find command line and if you add a path name type argument past that expanded alias, you get find arguments in the wrong order.

A general solution for your problem does not exist since you may need to add further find arguments before or after the path to be excluded depending on the situation.

You may try:

find() {
    command find "$1̈́" ! -path '*.sync' "$@"

but this only allows one path type argument.

  • Or you could use -type d -name '*.sync*' -prune -o.
    – Kusalananda
    Jul 14 '18 at 14:45
  • I have GNU find 4.7.0 and it has a -not operator. But yeah, that approach also came to mind, but would be kinda annoying to get working properly.
    – xeruf
    Jul 14 '18 at 15:30
  • I also have GNU find and the -not operator is there. It functions the same as !. Jul 14 '18 at 16:03
  • This is still no reason to use it. GNUs -not is a method to create a vendor lock in. There is no reason not to use the ! since that existed at least 15 years before GNU find has been written.
    – schily
    Jul 14 '18 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.