Original find which works in OS X but not now in Ubuntu 16.04
find $HOME -type f -name "*.tex" -exec grep -l "masi" {} + | vim -R -
(simplified version still; you can omit vim
part but it just shows here that I am handling the results)
In Ubuntu 16.04, I get those permission denied -messages. I want to exclude permission denied messages from my find; actually those files seem to be mostly .dotFiles
drwx------ 2 root root 4096 touko 29 23:59 .gvfs
I cannot combine the code to my find of searching.
So find all but exclude those files with permission denied (! -readable -prune
).
Pseudocode
find $HOME -type f -name "*.tex" \
-o ! -readable -prune -o \
-exec grep -l "masi" {} +
but it seems to expand too much by giving a massive list etc messages
grep: /home/masi/.conda/envs/my_root/src/linux-headers-4.2.0-27/include/linux/power: Is a directory`
...
So different than the thing works in OS X.
I tried also unsuccessfully -perm a+r
instead of the parsing structure but I still get those permission denied -messages.
Reviewing Gilles' answer
My final solution is
find $HOME +perm 0666 -type f -name ...
because readable
is not POSIX and does not work in OSX.
How can you combine search and exclude in find?
... 2> /dev/null
).2> find.err
, then you can review the error log at your leisure.-o
:find . ! -readable -prune -o -name '*.txt'
is one of the comments on the answer you have accepted there... and it has 33 upvotes so really, you can't miss it...find [...] 2> >(grep -v 'permission denied')
will filter out those specific errors from standard error.