Reference ▶️ ▶️ ▶️ How to Redirect Output and Error to /dev/null in Linux
Some thing about the output of linux
- In the linux machine,
/dev/null
that will location where you can return null for your shell likecommand 2>&1 /dev/null
- There will have 3 three type of output which linux has
- Standard input (stdin) is designated with 0
- Standard output (stdout) is designated with 1
- Standard error (stderr) is designated with 2
What things we can play with this
- Redirect output to /dev/null in Linux
For example: You run
apt install curl
but you want your shell not return anything you can redirectoutput
into/dev/null
. It will be like
Usage: Used it when you don’t want stdout go to your shell, just removing the odd things and keep the important output
- Redirect error to /dev/null in Linux
For example: You run
find /
but you run with non root, so somecase you will have some permission error output to your shell. You can use/dev/null
for removing this messing stuff
- Awesome things, you can combine
stdout
andstderror
into one with this character&
Troubleshoot
Sometime you can use version
2
of combiningThe
2>&1
part means “redirect the error stream into the output stream”, so when you redirect the output stream, error stream gets redirected as well. Even if your program writes tostderr
now, that output would be discarded as well. (Sergey Kalinichenko)
Find this problem ▶️ ▶️ What is /dev/null 2>&1?