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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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 is Linux actually good for? What is Linux actually good for? Apr 12, 2025 am 12:20 AM

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

How to start apache How to start apache Apr 13, 2025 pm 01:06 PM

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

What to do if the apache80 port is occupied What to do if the apache80 port is occupied Apr 13, 2025 pm 01:24 PM

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

How to monitor Nginx SSL performance on Debian How to monitor Nginx SSL performance on Debian Apr 12, 2025 pm 10:18 PM

This article describes how to effectively monitor the SSL performance of Nginx servers on Debian systems. We will use NginxExporter to export Nginx status data to Prometheus and then visually display it through Grafana. Step 1: Configuring Nginx First, we need to enable the stub_status module in the Nginx configuration file to obtain the status information of Nginx. Add the following snippet in your Nginx configuration file (usually located in /etc/nginx/nginx.conf or its include file): location/nginx_status{stub_status

How to start monitoring of oracle How to start monitoring of oracle Apr 12, 2025 am 06:00 AM

The steps to start an Oracle listener are as follows: Check the listener status (using the lsnrctl status command) For Windows, start the "TNS Listener" service in Oracle Services Manager For Linux and Unix, use the lsnrctl start command to start the listener run the lsnrctl status command to verify that the listener is started

How to set up a recycling bin in Debian system How to set up a recycling bin in Debian system Apr 12, 2025 pm 10:51 PM

This article introduces two methods of configuring a recycling bin in a Debian system: a graphical interface and a command line. Method 1: Use the Nautilus graphical interface to open the file manager: Find and start the Nautilus file manager (usually called "File") in the desktop or application menu. Find the Recycle Bin: Look for the Recycle Bin folder in the left navigation bar. If it is not found, try clicking "Other Location" or "Computer" to search. Configure Recycle Bin properties: Right-click "Recycle Bin" and select "Properties". In the Properties window, you can adjust the following settings: Maximum Size: Limit the disk space available in the Recycle Bin. Retention time: Set the preservation before the file is automatically deleted in the recycling bin

How to restart the apache server How to restart the apache server Apr 13, 2025 pm 01:12 PM

To restart the Apache server, follow these steps: Linux/macOS: Run sudo systemctl restart apache2. Windows: Run net stop Apache2.4 and then net start Apache2.4. Run netstat -a | findstr 80 to check the server status.

How to optimize the performance of debian readdir How to optimize the performance of debian readdir Apr 13, 2025 am 08:48 AM

In Debian systems, readdir system calls are used to read directory contents. If its performance is not good, try the following optimization strategy: Simplify the number of directory files: Split large directories into multiple small directories as much as possible, reducing the number of items processed per readdir call. Enable directory content caching: build a cache mechanism, update the cache regularly or when directory content changes, and reduce frequent calls to readdir. Memory caches (such as Memcached or Redis) or local caches (such as files or databases) can be considered. Adopt efficient data structure: If you implement directory traversal by yourself, select more efficient data structures (such as hash tables instead of linear search) to store and access directory information

See all articles