[Linux](EN) Ignore stderr in terminal prompt using /dev/null and redirect

Redirect stderr to /dev/null so that ignore prints of standard errors in terminal prompt.


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)
  • Redirect


Terms

What is /dev/null?

  • /dev/null: Device file that discards all data written to it but reports that the write operation succeeded.
  • You can ignore standard error on screen when you write stderr to /dev/null.

What is redirect?

  • Redirect('>'): Redirect standard streams to user-specified locations like file or other stream.
  • Reference: Redirection (computing)


Usage example

Ignore stderr in find command

  • It prints Permission denied as stderr
$ find / | grep neutron
find: ‘/run/docker’: Permission denied
find: ‘/run/containerd’: Permission denied
find: ‘/run/lxcfs’: Permission denied
find: ‘/run/sudo’: Permission denied
find: ‘/run/log/journal/50739525d1fb4eac9e863478fb990fed’: Permission denied
find: ‘/run/lvm’: Permission denied
  • After redirect stderr to /dev/null, there is no Permission denied
  • 2 represents stderr
find / 2> /dev/null | grep neutron
/home/twpower/test/neutron_patched
/home/twpower/test/neutron_patched/LICENSE
/home/twpower/test/neutron_patched/.gitignore
/home/twpower/test/neutron_patched/bin
...


Reference