What I want to achieve
- find a specific file which I have read permission for
- ignore error lines of "Permission denied"
What didn't work
Firstly I tried this command to remove the "Permission denied" lines.
$ find /path/ -readable | grep -v "denied"
However, it didn't work.
That's because the error messages are on a separate stream from the grep
targets.
The "Permission denied" messages are printed to the standard error stream (stderr), while the grep
command only filters the standard output stream (stdout).
How to tackle
- Redirect both output streams using
2>&1
which redirects stderr(file descriptor 2) to stdout(file descriptor 1).
$ find /path/ -readable 2>&1 | grep -v "denied"
- suppress stderr putting away into
/dev/null/
, a special file that discards any data written to it, effectively silencing stderr.
$ find /path/ -readable 2>/dev/null
Top comments (0)