/dev/null belongs to the character special file, it belongs to the empty device, it is a special device file, it discards all the data written in it, the content written to it will be lost forever, and there is no content to read.
We use the file command to see if the type is a character special file.
file /dev/null/dev/null: Character Special
Attempt to read
cat /dev/null
Nothing can be read, just like a black hole.
So we usually think of/dev/null as a dumpster, not something to throw in. For example, to clear the contents of a file.
Example:
ls >>cat a.txta.txtpasswdtime. SH cat /dev/null >cat a.txt
You can also read the contents of a file into the/dev/null. But when the file does not exist, the return is wrong. We can add the number 2 to the front.
cat test.txt >/dev/nullcatcat test.txt 2>/ dev/NULL
Both the general standard output and the standard error output are screens, so the error message is still output on the screen. This number represents the standard output.
0: Represents the standard input stream (stdin),
1: Indicates standard output (stdout).
2: Indicates standard error output (stderr)
The above is to redirect the standard error (2) output to/dev/null, so no more error prompts are displayed on the screen.
"Linux"/dev/null effect