What does stream mean in linux?

青灯夜游
青灯夜游Original
2023-03-17 09:55:421866browse

In Linux, stream means data flow, which is a string of data read in a certain order, so the direction of the data flow is the reading order of the data flow. The process of the Linux system importing the output results after reading the data into other files is called redirected data flow. After inputting a command under Linux and running it, two results will be displayed on the screen: the result of successful operation is the standard output, and the result of the failed operation is the standard error output; if not processed, they will be displayed on the screen and redirected through the data flow. You can save it to other files.

What does stream mean in linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

In Linux, stream means data flow.

What does stream (data stream) mean?stream (data stream) is a string of data read in a certain order, so the direction of the data flow It is the reading order of the data stream.

Data stream is originally a concept used in the field of communications and represents a sequence of digitally encoded signals used in transmission of information. This concept was first proposed by Henzinger in 1998 in Document 87. He defined a data stream as "a sequence of data that can only be read once in a predetermined order."

Linux system redirection data flow is to import the output results after reading the data into other files.

Linux data flow redirectionData flow redirection is simply to locate the input data source or output data of a certain command to other files. Everything under Linux is a file. The files here can be device files, ordinary files, etc.

1. stdin stdout stderr

stdin: standard input. Refers to some information provided for the command to run.
stdout: Standard output. Refers to the correct information returned by command execution.
stderr: Standard error output. Refers to the error message returned after the command execution fails.

The relationship between these three and the command is usually as follows:

stdin        
stderr        
stdout        
File
Command
Screen/File
Screen/File

In the Linux environment, after we enter a command and run it, two results will be displayed on the screen : The result of a successful operation is the standard output, and the result of a failed operation is the standard error output.

  • Standard output (STDOUT): Standard output refers to the correct information returned by command execution.

  • Standard error output (STDERR): Standard error output refers to the error information returned by command execution.

If STDOUT and STDERR are not processed, they will be displayed on the screen. They can be stored in other files through data flow redirection, and stored in files. The special characters are:

  • Standard input stin: code is 0, use 38d33e17f0a8d6f59380fac1f7480e57 or

  • standard error output stderr: code is 2, use 2> or 2>>

## 2. Use of data stream redirection

  • stdout: standard output redirection. What is redirected here is the correct output.
find / -name '.bashrc' > ~/out_right
This command directs the correct output to the file

~/out_right. If ~/out_right does not exist, it will be created automatically. Because the error message is not processed, the error output is output to the screen terminal by default. At this time, the terminal will only display the error output.

  • stderr: Standard error output redirection. What is redirected here is the error output.
find / -name '.bashrc' 2> ~/out_error
This command directs the error output to the file

~/out_error. If ~/out_error does not exist, it will be created automatically. Because the correct information is not processed, the correct output is output to the screen terminal by default. At this time, the terminal will only display the correct output (if the specified file is not found, there will be no output on the screen).

  • stdin: Standard input is generally used to replace keyboard input.
cat > catfile 921c721c6f87abc2b290907d138e2d29<code>. </code>cat<code> is the command to view the file. Here, the file </code>~/.bashrc<code> is directly read and then output to </code>catfile<code>. </code><p><a id="3_2_47"></a>##3、<span style="font-size: 18px;"><strong></strong>>>,2>>,37e43ca4bf4c252f17f42073aed3a956><ul>(<li>ACCUMULATION<code>): Append standard output. </code>cmd > file1<strong>, the command </strong>cmd<code> will output </code>stdout<code> to </code>file1<code>, if </code>fiel1<code> previously existed, and If there is data, then </code>file1<code> will be cleared in advance and then written to </code>stdout<code>. When using the command </code>cmd >> file1<code>, the </code>file1<code> file will not be cleared in advance, but the input data will be added directly to the end of the file. </code><code></code>2>></li> (<li>cumulative<code>): Additional standard error output. Similar to </code>>><strong>. </strong><code></code>23481cda0c3ce8ab57c4f0d58713931b list 2>&1</li>
</ul></span></p> . <p>2>&1<code> in this code can be understood as redirecting standard error output (code 2) to standard output (code 1). Then </code>> list<code>redirects standard output to the file </code>list<code>. Because standard error output is directed as standard output, all output ends up being directed to file </code>list<code>. </code><code>Related recommendations: "</code>Linux Video Tutorial</p>"<p></p>

The above is the detailed content of What does stream mean in linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn