1

Wanting to find for files except for those, that are in /home directory (directly or in one of subdirectories of any level), I run the following command:

find / ! -path '/home/*'

However, I get error messages with "Permission Denied" message, like the following:

find: '/home/user/here/is/some/file': Permission denied

I don't care that it is "permission denied" per se, what I don't like is that it even tries to search there.

At first I thought that could be because there is some symbolic link from other places on FS, that references a directory inside /home/user/, but then I tried with -H option like this:

find -H / ! -path '/home/*'

and it still listed those files/directories inside /home/*.

Any ideas, how to rectify that?

Student4K
  • 119
  • 2

1 Answers1

2

The -path component is evaluated for every possible path. It doesn't short-circuit the search - you need -prune for that

find / -path '/home/*' -prune -o -print
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • In particular, it doesn't interpret the contents of the pattern to determine that it will match everything under /home. Here, it would be relatively simple to do, but the pattern could be something like /home/*x, which requires looking at every file, and there could be a more complex set of conditions (and actions) than just a single -path. – ilkkachu Dec 05 '20 at 20:55