Use of/dev/null in linux, devnull
Author: iamlaosong
I have a data import program that uses crontab to set scheduled execution. Sometimes, when data needs to be re-imported, it runs once manually. The result shows that the manual import time is longer than the scheduled execution time, the reason is that it is estimated that it is time-consuming because the name and sequence number of the imported data are displayed for each piece of data imported in the program, the output can be redirected to/dev/null. For example:
./Impx. sh>/dev/null
You can regard/dev/null as a "black hole", which is very equivalent to a write-only file, and all the content written to it will be lost forever.
However, if you try to read content from it, nothing can be read. However,/dev/null is very useful for both the command line and script.
1. Disable Standard output
Cat $ filename>/dev/null
# The file content is lost without being output to the standard output.
2. Forbidden standard error
Rm $ badname 2>/dev/null
# The error message [standard error] is thrown to the Pacific Ocean.
3. Disable Standard output and standard error output.
Cat $ filename 2>/dev/null
4. Clear Log File Content
Cat/dev/null>/var/log/messages
#:>/Var/log/messages has the same effect, but no new processes are generated (because: built-in)