"Linux"/dev/null effect

Source: Internet
Author: User

/dev/null belongs to the character special file, it belongs to the empty device, it is a special device file, it discards all the data written in it, the content written to it will be lost forever, and there is no content to read.

We use the file command to see if the type is a character special file.

file /dev/null/dev/null: Character Special

Attempt to read

cat /dev/null

Nothing can be read, just like a black hole.

So we usually think of/dev/null as a dumpster, not something to throw in. For example, to clear the contents of a file.

Example:

ls >>cat  a.txta.txtpasswdtime. SH  cat /dev/null >cat a.txt

You can also read the contents of a file into the/dev/null. But when the file does not exist, the return is wrong. We can add the number 2 to the front.

cat test.txt   >/dev/nullcatcat test.txt   2>/ dev/NULL

Both the general standard output and the standard error output are screens, so the error message is still output on the screen. This number represents the standard output.

0: Represents the standard input stream (stdin),

1: Indicates standard output (stdout).

2: Indicates standard error output (stderr)

The above is to redirect the standard error (2) output to/dev/null, so no more error prompts are displayed on the screen.

"Linux"/dev/null effect

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.