Use of/dev/null in linux, devnull

Source: Internet
Author: User

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)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.