Set/Dev/nullAs"Black hole".It is very equivalent to writing only files. All the content written to it will be lost forever. However, you cannot read anything when trying to read the content from it. However,
/Dev/nullIt is very useful for command lines and scripts.
DisableStandard output.
1 cat $ FILENAME>/dev/null 2 # The file content is lost without being output to the standard output. |
DisableStandard Error
1 RM $ badname 2>/dev/null 2 # the error message [standard error] is thrown to the Pacific Ocean. |
Disable Standard output and standard error output.
1 cat $ filename 2>/dev/null 2 # If "$ FILENAME" does not exist, no error message is prompted. 3 # If "$ FILENAME" exists, the file content will not be printed to the standard output. 4 # therefore, therefore, the aboveCodeIt does not output any information at all. 5 # It is very useful when you only want to test the exit code of the command and do not want to have any output. 6 # ----------- exit the test command begin -------------------- #7 # ls dddd 2>/dev/null 8 # echo $? // Exit code of the output command: 0 indicates that the command is executed normally, and 1-indicates that an error occurs. 9 # ----------- exit of the test command end ----------- #10 # Cat $ filename &>/dev/null 11 # alternatively, it can be pointed out by Baris Cicek. |
Clear Log File Content
1 CAT/dev/null>/var/log/messages 2 #:>/var/log/messages has the same effect, but no new process is generated. (Because: built-in) 3 4 CAT/dev/null>/var/log/wtmp |
Example 28-1. Hide the cookie and stop using it
1 If [-f ~ /. Netscape/cookies] # Delete. 2 then 3 Rm-f ~ if any ~ /. Netscape/cookies 4 fi 5 6 ln-S/dev/null ~ /. Netscape/cookies 7 # Now all cookies will be thrown into the black hole and will not be saved on the disk. |
From: Advanced bash-scripting Guide: an in-depth injection of the art of shell Scripting