Table of Contents
What does stream (data stream) mean?
Linux data flow redirection

What does stream mean in linux?

Mar 17, 2023 am 09:55 AM
linux stream

<blockquote><p>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. </p></blockquote> <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/202303/17/2023031709544952034.jpg" class="lazy" alt="What does stream mean in linux?" ></p> <p>#The operating environment of this tutorial: linux7.3 system, Dell G3 computer. </p> <p><strong>In Linux, stream means data flow. </strong></p> <h2 id="strong-What-does-stream-data-stream-mean-strong"><strong>What does stream (data stream) mean?</strong></h2> <p>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. </p> <p>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." </p> <p>Linux system redirection data flow is to import the output results after reading the data into other files. </p> <h2 id="strong-Linux-data-flow-redirection-strong"><strong>Linux data flow redirection</strong></h2> <p>Data 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. </p> <p><a id="1_stdin_stdout_stderr_5"></a><span style="font-size: 18px;"><strong>1. stdin stdout stderr</strong></span></p> <blockquote><p><code>stdin</code>: standard input. Refers to some information provided for the command to run. <br><code>stdout</code>: Standard output. Refers to the correct information returned by command execution. <br><code>stderr</code>: Standard error output. Refers to the error message returned after the command execution fails. </p></blockquote> <p>The relationship between these three and the command is usually as follows:</p> <div class="mermaid sequence-diagram"><svg id="mermaid-svg-43Q0mtxvjga7WpCa" width="100%" xmlns="http://www.w3.org/2000/svg" height="158" style="max-width: 436.46875px;" viewbox="0 0 436.46875 158"><style>#mermaid-svg-43Q0mtxvjga7WpCa {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-43Q0mtxvjga7WpCa .error-icon{fill:#552222;}#mermaid-svg-43Q0mtxvjga7WpCa .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-43Q0mtxvjga7WpCa .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-43Q0mtxvjga7WpCa .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-43Q0mtxvjga7WpCa .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-43Q0mtxvjga7WpCa .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-43Q0mtxvjga7WpCa .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-43Q0mtxvjga7WpCa .marker{fill:#333333;stroke:#333333;}#mermaid-svg-43Q0mtxvjga7WpCa .marker.cross{stroke:#333333;}#mermaid-svg-43Q0mtxvjga7WpCa svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-43Q0mtxvjga7WpCa .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-43Q0mtxvjga7WpCa .cluster-label text{fill:#333;}#mermaid-svg-43Q0mtxvjga7WpCa .cluster-label span{color:#333;}#mermaid-svg-43Q0mtxvjga7WpCa .label text,#mermaid-svg-43Q0mtxvjga7WpCa span{fill:#333;color:#333;}#mermaid-svg-43Q0mtxvjga7WpCa .node rect,#mermaid-svg-43Q0mtxvjga7WpCa .node circle,#mermaid-svg-43Q0mtxvjga7WpCa .node ellipse,#mermaid-svg-43Q0mtxvjga7WpCa .node polygon,#mermaid-svg-43Q0mtxvjga7WpCa .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-43Q0mtxvjga7WpCa .node .label{text-align:center;}#mermaid-svg-43Q0mtxvjga7WpCa .node.clickable{cursor:pointer;}#mermaid-svg-43Q0mtxvjga7WpCa .arrowheadPath{fill:#333333;}#mermaid-svg-43Q0mtxvjga7WpCa .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-43Q0mtxvjga7WpCa .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-43Q0mtxvjga7WpCa .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-43Q0mtxvjga7WpCa .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-43Q0mtxvjga7WpCa .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-43Q0mtxvjga7WpCa .cluster text{fill:#333;}#mermaid-svg-43Q0mtxvjga7WpCa .cluster span{color:#333;}#mermaid-svg-43Q0mtxvjga7WpCa div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-43Q0mtxvjga7WpCa :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}</style> <g><g class="output"><g class="clusters"></g><g class="edgePaths"><g class="edgePath LS-A LE-B" style="opacity: 1;" id="L-A-B"><path class="path" d="M54.40625,79L61.493489583333336,79C68.58072916666667,79,82.75520833333333,79,96.9296875,79C111.10416666666667,79,125.27864583333333,79,132.36588541666666,79L139.453125,79" marker-end="url(#arrowhead34)" style="fill:none"></path><defs><marker id="arrowhead34" viewbox="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath LS-B LE-C" style="opacity: 1;" id="L-B-C"><path class="path" d="M229.451171875,56L237.5322265625,51.833333333333336C245.61328125,47.666666666666664,261.775390625,39.333333333333336,277.8069661458333,35.166666666666664C293.8385416666667,31,309.7395833333333,31,317.6901041666667,31L325.640625,31" marker-end="url(#arrowhead35)" style="fill:none"></path><defs><marker id="arrowhead35" viewbox="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath LS-B LE-D" style="opacity: 1;" id="L-B-D"><path class="path" d="M229.451171875,102L237.5322265625,106.16666666666667C245.61328125,110.33333333333333,261.775390625,118.66666666666667,277.8069661458333,122.83333333333333C293.8385416666667,127,309.7395833333333,127,317.6901041666667,127L325.640625,127" marker-end="url(#arrowhead36)" style="fill:none"></path><defs><marker id="arrowhead36" viewbox="0 0 10 10" refx="9" refy="5" markerunits="strokeWidth" markerwidth="8" markerheight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g></g><g class="edgeLabels"><g class="edgeLabel" style="opacity: 1;" transform="translate(96.9296875,79)"><g transform="translate(-17.5234375,-13)" class="label"><rect rx="0" ry="0" width="35.046875" height="26"></rect><foreignobject width="35.046875" height="26"><div style="display: inline-block; white-space: nowrap;"> <span id="L-L-A-B" class="edgeLabel L-LS-A' L-LE-B">stdin</span>        </div></foreignobject></g></g><g class="edgeLabel" style="opacity: 1;" transform="translate(277.9375,31)"><g transform="translate(-21.453125,-13)" class="label"><rect rx="0" ry="0" width="42.90625" height="26"></rect><foreignobject width="42.90625" height="26"><div style="display: inline-block; white-space: nowrap;"> <span id="L-L-B-C" class="edgeLabel L-LS-B' L-LE-C">stderr</span>        </div></foreignobject></g></g><g class="edgeLabel" style="opacity: 1;" transform="translate(277.9375,127)"><g transform="translate(-22.703125,-13)" class="label"><rect rx="0" ry="0" width="45.40625" height="26"></rect><foreignobject width="45.40625" height="26"><div style="display: inline-block; white-space: nowrap;"> <span id="L-L-B-D" class="edgeLabel L-LS-B' L-LE-D">stdout</span>        </div></foreignobject></g></g></g><g class="nodes"><g class="node default" style="opacity: 1;" id="flowchart-A-18" transform="translate(31.203125,79)"><rect rx="5" ry="5" x="-23.203125" y="-23" width="46.40625" height="46" class="label-container"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-13.203125,-13)"><foreignobject width="26.40625" height="26"><div style="display: inline-block; white-space: nowrap;">File</div></foreignobject></g></g></g><g class="node default" style="opacity: 1;" id="flowchart-B-19" transform="translate(184.84375,79)"><rect rx="5" ry="5" x="-45.390625" y="-23" width="90.78125" height="46" class="label-container"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-35.390625,-13)"><foreignobject width="70.78125" height="26"><div style="display: inline-block; white-space: nowrap;">Command</div></foreignobject></g></g></g><g class="node default" style="opacity: 1;" id="flowchart-C-21" transform="translate(377.0546875,31)"><rect rx="5" ry="5" x="-51.4140625" y="-23" width="102.828125" height="46" class="label-container"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-41.4140625,-13)"><foreignobject width="82.828125" height="26"><div style="display: inline-block; white-space: nowrap;">Screen/File</div></foreignobject></g></g></g><g class="node default" style="opacity: 1;" id="flowchart-D-23" transform="translate(377.0546875,127)"><rect rx="5" ry="5" x="-51.4140625" y="-23" width="102.828125" height="46" class="label-container"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-41.4140625,-13)"><foreignobject width="82.828125" height="26"><div style="display: inline-block; white-space: nowrap;">Screen/File</div></foreignobject></g></g></g></g></g></g></svg></div> <p>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. </p> <ul style="list-style-type: disc;"> <li><p>Standard output (STDOUT): Standard output refers to the correct information returned by command execution. </p></li> <li><p>Standard error output (STDERR): Standard error output refers to the error information returned by command execution. </p></li> </ul> <p>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: </p> <ul style="list-style-type: disc;"> <li><p>Standard input stin: code is 0, use <code><</code> or <code><<</code></p></li><li><p>Standard output stout: code is 1, use <code>></code> or <code>>></code></p></li> <li><p> standard error output stderr: code is 2, use <code>2></code> or <code>2>></code></p></li> </ul> <p><a id="2__21"></a><span style="font-size: 18px;">## 2. Use of data stream redirection<strong></strong></span></p> <ul><li>stdout<code>: standard output redirection. What is redirected here is the correct output. </code> </li></ul> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">find / -name '.bashrc' > ~/out_right</pre><div class="contentsignin">Copy after login</div></div>This command directs the correct output to the file <p>~/out_right<code>. If </code>~/out_right<code> 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. </code></p> <ul><li>stderr<code>: Standard error output redirection. What is redirected here is the error output. </code> </li></ul> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">find / -name '.bashrc' 2> ~/out_error</pre><div class="contentsignin">Copy after login</div></div>This command directs the error output to the file <p>~/out_error<code>. If </code>~/out_error<code> 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). </code></p> <ul><li>stdin<code>: Standard input is generally used to replace keyboard input. </code> </li></ul> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">cat > catfile < ~/.bashrc</pre><div class="contentsignin">Copy after login</div></div></ul><p>cat<code>Without any parameters after the command, cat will read the data from the keyboard. Using standard input, direct the input source to the file </code>~/.bashrc<code>. Then locate the standard output to the </code>catfile<code> file via </code>><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>>,<<<code><strong></strong></code></span></p>##>><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><<</li> (<li> specifies the end keyword <code>): followed by the input character </code> ending with <strong>. The keyword must be on its own line, otherwise it will be invalid. </strong><code>4a92b24db45be3e63a307e31d1bac26e</blockquote>There is more than one implementation method, let’s choose the better-understood writing method<p>find / -name .bashrc > 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></pre>

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

See all articles