DEV Community

mich0w0h
mich0w0h

Posted on

1

Linux find: remove error lines from outputs

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"
Enter fullscreen mode Exit fullscreen mode

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

  1. 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"
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more