The use of/dev/null under Linux

Source: Internet
Author: User

Iamlaosong

I have a data import program, with Crontab set timed execution, sometimes the data need to re-import, on the human run once, the results found that the time for manual import is greater than the timing of the execution time, the reason, the initial estimate is to show the flowers, because the program in each import a data, Displays the name of the imported data and the record ordinal, to save time, you can redirect the output to/dev/null. Such as:

./impx.sh >/dev/null

You can think of/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.

And try to read it from there. However,/dev/null is very useful for command lines and scripts.

1. Prohibit standard output

Cat $filename >/dev/null
# file content is missing, not output to standard output.

2. Prohibit standard error

RM $badname 2>/dev/null
# This error message [standard ERROR] has been thrown into the Pacific Ocean.

3, prohibit the output of standard output and standard error.

Cat $filename 2>/dev/null >/dev/null

4. Clear Log File contents

Cat/dev/null >/var/log/messages
#: >/var/log/messages has the same effect, but does not produce new processes. (because: Built-in)

The use of/dev/null under Linux

Related Article

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.