What is the difference between echo and/dev/null in command for clearing file content?

Source: Internet
Author: User
Tags echo command

What is the difference between echo and/dev/null in command for clearing file content?

We know that there are many methods to clear the file content. This article only talks about the differences between echo "And/dev/null.

1. What is the black hole device/dev/null?

In Linux, the null device is basically used to discard output streams that are no longer needed by a process, or as a blank file of an input stream. These can usually be achieved through the redirection mechanism.

Therefore, the/dev/null device file is a special file. It will empty all input sent to it, and its output can be considered as an empty file.

In addition, you can use the cat command to display/dev/null and redirect the content to a file to clear the file. By using cat/dev/null, the file size is 0 bytes.

Ii. What are the main differences between the two?

Null strings are not equivalent to null. A string indicates that it is a specific thing, but its content may be empty, but null means that a thing does not exist.

For this reason, when you redirect the echo command output to a file as input and use the cat command to view the content of the file, you will see a blank line (an empty string ).

To use null as the output input to the file, you should use the-n option, which will tell echo not to output the new line ending with the command above.

Iii. Practical Operation

Use cat/dev/null. The file size is 0.

When echo "" is used, the file size is 1, because echo only writes an empty string to the file. If you want to set the file size to 0, use echo-n ""

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.