/dev/null, from the name can be clearly seen as an empty file (write to/dev/null all lost, read/dev/null when you return to EOF), then you will be very puzzled, what is the use of him, please see below to listen to me, perhaps you have seen in a lot of scripts Dev/null, the specific summary of several common uses. prohibition of standard output.eg:Cat $filename >/dev/null# The file content is lost and will not be exported to standard output. ii. prohibition of standard errorseg:RM $badname 2>/dev/null#删除文件错误时, there will be no hint to the terminal, have been thrown into the/dev/null Third, prohibit the standard output and standard error output.EG1:cat $filename 2>/dev/null >/dev/null# if "$filename" does not exist, there will be no error message prompts.# if "$filename" exists, the contents of the file are not printed to standard output.# Therefore, the above code does not output any information at all.# It is useful when you want to test only the exit code of a command without any output. EG2:#-----------The exit begin----------------------of the test command #ls dddd 2>/dev/null 8echo $? Output command exit code: 0 for the command to execute correctly, 1-255 for error. #-----------The exit end-----------of the test command #Cat $filename &>/dev/null Iv. Clear the contents of the log fileeg:cat/dev/null >/var/log/messages#: >/var/log/messages has the same effect, but does not produce a new process. (because: is built)cat/dev/null >/var/log/wtmp v. Hide cookies and no longer be usedeg:if [f ~/.netscape/cookies] # if present, delete. thenrm-f ~/.netscape/cookiesfiln-s/dev/null ~/.netscape/cookies# Now all cookies will be discarded and not saved on disk.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.