Hello everyone, I am Liang Xu. As we all know, in Linux, everything is a file, including device files. In the process of work, we often see Technically speaking, However, when you want to write data to In this case, what is the use of Standard output file and standard error output file A command-line program can generate two types of output: standard output and standard error output. Standard output is recorded to the standard output file stdout, and standard error output is recorded to the standard error output file stderr. By default, standard output and standard error files are associated with your terminal window (or console). This means that anything sent to standard output or standard error will be displayed on your screen. However, through redirection in the shell, you can change this behavior. For example, you can redirect standard output to a file. This way, the standard output information will not be displayed on the screen, it will be saved to that file so that you can view it later, or you can redirect the standard output information to another physical device, such as a digital LED or LCD display. Some common redirection methods are as follows:
Use /dev/null to clear unnecessary output Since there are two types of output: standard output and standard error output, the first use of If you want to find files related to power settings by looking for files with the string
Since there are many files in the These error messages can clutter the screen and wash out important information. Since
In this way, the displayed information is much cleaner and clearer. Sometimes, we may not want to see the contents of standard output, but instead want to see the contents of standard error, so we can redirect standard output to
The above screenshot shows that without redirecting the output, the ping command displays its normal output when the packets can reach the destination host. As for the first command, when the network is connected, the screen shows nothing, but once it is disconnected from the target machine, the screen only shows the error message.
In this example, standard output will not be displayed and error messages will be saved to a file called Redirect all output to /dev/null Sometimes, we may not want to see any output, so there are two ways to do this.
The string One important point to note here is that order is also very important. If you swap the redirect parameters to look like this:
It just doesn't work the way you expected. That's because once
In this example, Other practical examples of redirecting output to /dev/null If you want to know how fast your disk can read sequential data, you can use the For the following command, the parameter The following test is not very accurate, but it is enough to illustrate the problem.
The above is a practical scenario. Here is another scenario. At some point you might want to know how fast you can download something from a particular server. But you don't want to write unnecessary things to the disk, so at this time, you can write the content to
in conclusion This article introduces several practical uses of the This concludes this article about the various practical uses of virtual device files in Linux systems. For more relevant content on the usage of Linux virtual device files, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: What is the length of a function in js?
>>: MySQL encoding utf8 and utf8mb4 utf8mb4_unicode_ci and utf8mb4_general_ci
1. Docker ps lists containers 2. Docker cp copies...
Color is one of the most important elements for a...
html2canvas is a library that generates canvas fr...
Table of contents MySQL basic common commands 1. ...
Table of contents Preface Installation and Usage ...
Table of contents Preface Implementation ideas Ef...
Table of contents 1.0 Introduction 2.0 Docker Ins...
download http://nginx.org/en/download.html Unzip ...
VUE uses vue-seamless-scroll to automatically scr...
Benefits of Prepare The reason why Prepare SQL is...
1. Introduction to Logrotate tool Logrotate is a ...
Preface When we deploy applications to servers as...
In the previous article, we introduced: MySQL8.0....
Find the problem When we display the contents in ...
<br />Conditional comments are a feature uni...