beforehand: this evolved from a general question (I thought it was the case with every folder) to this specific corner case.
as it seemed that a few other people are as curious as myself, I decided to not delete this question but rework it.
Let's say I want to list all items contained direct in my home folder, except the dot files & folders. IMHO, the following find command should do this (I explicitly wrote "dot items", because if you use a .hidden
file the "hidden items" may differ):
find $HOME/ -mindepth 1 -maxdepth 1 -path "$HOME/.*" -prune -o -print
-mindepth 1
to ensure that $HOME itself is not included, -maxdepth 1
to limit to one folder level, -path "$HOME/.*" -prune
to exclude everything in the home folder starting with a dot and -o -print
to ensure that not the excluded elements are in the output according to the man page.
So far, so good. It kind of works (even if there are dot-folders for which you don't have the permissions), but it starts to choke on $HOME/.gvfs
although it shouldn't be accessed at all due to -path ... -prune
:
/home/user/file a
/home/user/folder b
...
find: '/home/user/.gvfs': Permission denied
/home/user/.gvfs
...
/home/user/file z
I know I can use -perm
at find
and 2> /dev/null
to work around it, but what really appalled me is, that /home/user/.gvfs
is included in the list (although all other dot items are excluded)!!!
and I'm pretty sure some not so careful people are tempted to get rid of the error with 2> /dev/null
and move on. ...if they recognize the error at all, because at longer lists with a few 100 lines you have to explicitly check for errors with something like adding 1> /dev/null
prior to working with that command.
really ignoring a directory/tree?
Why is find
trying to access /home/user/.gvfs
at all, despite -maxdepth 1
or at least -prune
should prevent this? e.g. from the man page:
‘-prune’ action (which only prevents further descent [...])
even in an older man page (installed on my system) for -path
it is stated:
To ignore a whole directory tree, use -prune rather than checking every file in the tree.
dangerous listing of an "ignored" directory itself!
If all /home/user/.*
would be really ignored, perhaps the second part of my question won't be necessary, as it seems to me this is because of an internal error:
why is /home/user/.gvfs
still in the list and how to prevent it? Is there a way without fiddling around with -user
/-perm
and 2> /dev/null
for every find
command (at least with a -prune
action)?
future usage -> efficiency?
What is really ignored with -prune
(or at least with -path ... -prune
)?
If with -prune
still (nearly) all files are checked, I would ditch using this complicated option and rather use !
or -not
, especially as -prune
is apparently much more error-prone.
-maxdepth 2
and without-prune
i get the permission error, which is obvious. || it seems that the older machine where i tested it, is somehow f*ed up or at least its gvfs. :-($HOME/.gvfs
would match the-prune
test (even if f*ed up)! but i'm afraid i'll never know...