Your command
find ~ -path "/home/user/sandboxes/*" -prune -o -name 'some-file.vmdk'
prints
/home/user/sandboxes/debian7.amd64.buildd
/home/user/sandboxes/debian9.amd64.buildd
because the default action when no action is supplied is to output the found pathnames. The above pathnames are found, and then those paths are pruned. Pruning a search path does not exclude these pathnames from being printed.
However, if you add -print
to the very end, as in
find "$HOME" -path "$HOME/sandboxes" -prune -o -name 'some-file.vmdk' -print
then those pathnames would not be printed. This is because now you have an explicit action (the -print
), so no default actions are triggered. The -print
only applies to the right hand side of -o
.
Note that the *
is not needed, and that the variable $HOME
is easier to work with than ~
, especially in scripts.
Your first command,
find ~ -not -path "~/sandboxes/*" -name 'some-file.vmdk'
very likely does not work as ~
is not expanded within quotes.
Assuming you used $HOME
instead, it also does not prune the search path, which means it would still enter ~/sandboxes
, but it would never print any pathnames from beneath that path. Since it enters the directory, it would still give you the permission errors when it reaches the inaccessibly directories.
-path "~/sandboxes/*"
with-path "$HOME/sandboxes/*"
some-file.vmdk
only? It may be useful to state explicitly what the expected output is, we may wonder if you want the path/home/user/sandboxes
(not its content) to be printed or not.find
not to even enter/home/user/sandboxes