目录
stream(数据流)是什么意思
Linux数据流重定向
首页 运维 linux运维 linux中stream什么意思

linux中stream什么意思

Mar 17, 2023 am 09:55 AM
linux stream

<blockquote><p>在linux中,stream是数据流的意思,就是按一定顺序读取的一串数据,所以数据流的方向就是数据流的读取顺序。Linux系统把数据读取后输出的结果导入到其他文件中的过程称为重定向数据流。Linux下输入一段命令并运行以后,屏幕里会显示两种结果:运行成功结果即标准输出、运行失败结果即标准错误输出;如果不做处理,它们都会显示在屏幕上,而通过数据流重定向就可将其储存到其他的文件中。</p></blockquote> <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/202303/17/2023031709544952034.jpg" class="lazy" alt="linux中stream什么意思" ></p> <p>本教程操作环境:linux7.3系统、Dell G3电脑。</p> <p><strong>在linux中,stream是数据流的意思。</strong></p> <h2 id="strong-stream-数据流-是什么意思-strong"><strong>stream(数据流)是什么意思</strong></h2> <p>stream(数据流)就是按一定顺序读取的一串数据,所以数据流的方向就是数据流的读取顺序。</p> <p>数据流最初是通信领域使用的概念,代表传输中所使用的信息的数字编码信号序列。这个概念最初在1998年由Henzinger在文献87中提出,他将数据流定义为“只能以事先规定好的顺序被读取一次的数据的一个序列”。</p> <p>Linux系统重定向数据流就是把数据读取后输出的结果导入到其他文件中。</p> <h2 id="strong-Linux数据流重定向-strong"><strong>Linux数据流重定向</strong></h2> <p>数据流重定向简单来说就是将某条命令的输入数据来源或输出数据定位到其他的文件。Linux下一切皆文件。这里的文件可以是设备文件、普通文件等。</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>:标准输入。指的是为命令运行所提供的一些信息。<br><code>stdout</code>:标准输出。指的是命令执行所返回的正确信息。<br><code>stderr</code>:标准错误输出。指的是命令执行失败后所返回的错误信息。</p></blockquote> <p>这三者与命令的关系通常如下:</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>在Linux环境下,我们输入一段命令并运行以后,屏幕里会显示两种结果:运行成功结果即标准输出、运行失败结果即标准错误输出。</p> <ul style="list-style-type: disc;"> <li><p>标准输出(STDOUT): Standard output,指的是命令执行所返回的正确信息。</p></li> <li><p>标准错误输出(STDERR): Standard error output,指的是命令执行所返回的错误信息。</p></li> </ul> <p>如果不对STDOUT和STDERR做处理,他们都会显示在屏幕上,通过数据流重定向就可以将其储存到其他的文件中,而将其储存在文件中的特殊字符有:</p> <ul style="list-style-type: disc;"> <li><p>标准输入stin:代码为0,使用<code><</code>或<code><<</code></p></li><li><p>标准输出stout:代码为1,使用<code>></code>或<code>>></code></p></li> <li><p>标准错误输出stderr:代码为2,使用<code>2></code>或<code>2>></code></p></li> </ul> <p><a id="2__21"></a><span style="font-size: 18px;"><strong>2、数据流重定向的使用</strong></span></p> <ul><li> <code>stdout</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">登录后复制</div></div> <p>该命令将正确输出定向输入到文件<code>~/out_right</code>。如果<code>~/out_right</code>不存在,则自动创建。因为没对错误信息处理,错误输出默认输出到屏幕终端上,此时终端只会显示错误输出。</p> <ul><li> <code>stderr</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">登录后复制</div></div> <p>该命令将错误输出定向输入到文件<code>~/out_error</code>。如果<code>~/out_error</code>不存在,则自动创建。因为没对正确信息处理,正确输出默认输出到屏幕终端上,此时终端只会显示正确输出(如果没找到指定文件,屏幕没有输出)。</p> <ul><li> <code>stdin</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">登录后复制</div></div><p><code>cat</code>命令后不接任何参数,cat会从键盘读取数据。使用标准输入,将输入来源定向到文件<code>~/.bashrc</code>。然后通过<code>>将标准输出定位到<code>catfile</code>文件。<code>cat</code>是查看文件的命令,这里直接读取文件<code>~/.bashrc</code>然后将其输出到<code>catfile</code>。<p><a id="3_2_47"></a><span style="font-size: 18px;"><strong>3、</strong><code><strong>>>,2>>,<<</strong></code></span></p><ul><li><code>>></strong></code>(<strong>累加</strong>):附加标准输出。<code>cmd > file1</code>,命令<code>cmd</code>将<code>stdout</code>输出到<code>file1</code>中,如果<code>fiel1</code>此前存在,且有数据,那么<code>file1</code>会事先被清空,然后写入<code>stdout</code>。而使用命令<code>cmd >> file1</code>,不会预先清空<code>file1</code>文件,而是直接在文件末尾加上输入的数据。<li> <code>2>></code>(<strong>累加</strong>):附加标准错误输出。与<code>>></code>相似。</li> <li> <code><<</code>(<strong>指定结束关键字</strong>):后接<code>结束的输入字符</code>。关键字必须独占一行,否则无效。</li></ul>0b306e4fb0c25c47d39334395a4287d9<p>实现方法不止一种,我们取较好理解的写法<code>find / -name .bashrc > list 2>&1</code>。这段代码中的<code>2>&1</code>可以理解为,将标准错误输出(代码为2)重定向为标准输出(代码为1)。然后<code>> list</code>将标准输出重定向到文件<code>list</code>。因为标准错误输出被定向为标准输出,所以最后所有输出都被定向到文件<code>list</code>中。</li></span></p><p>相关推荐:《<a href="http://www.php.cn/course/list/33.html" target="_blank">Linux视频教程</a>》</p></pre>

以上是linux中stream什么意思的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

centos和ubuntu的区别 centos和ubuntu的区别 Apr 14, 2025 pm 09:09 PM

CentOS 和 Ubuntu 的关键差异在于:起源(CentOS 源自 Red Hat,面向企业;Ubuntu 源自 Debian,面向个人)、包管理(CentOS 使用 yum,注重稳定;Ubuntu 使用 apt,更新频率高)、支持周期(CentOS 提供 10 年支持,Ubuntu 提供 5 年 LTS 支持)、社区支持(CentOS 侧重稳定,Ubuntu 提供广泛教程和文档)、用途(CentOS 偏向服务器,Ubuntu 适用于服务器和桌面),其他差异包括安装精简度(CentOS 精

centos如何安装 centos如何安装 Apr 14, 2025 pm 09:03 PM

CentOS 安装步骤:下载 ISO 映像并刻录可引导媒体;启动并选择安装源;选择语言和键盘布局;配置网络;分区硬盘;设置系统时钟;创建 root 用户;选择软件包;开始安装;安装完成后重启并从硬盘启动。

Centos停止维护2024 Centos停止维护2024 Apr 14, 2025 pm 08:39 PM

CentOS将于2024年停止维护,原因是其上游发行版RHEL 8已停止维护。该停更将影响CentOS 8系统,使其无法继续接收更新。用户应规划迁移,建议选项包括CentOS Stream、AlmaLinux和Rocky Linux,以保持系统安全和稳定。

CentOS上GitLab的备份方法有哪些 CentOS上GitLab的备份方法有哪些 Apr 14, 2025 pm 05:33 PM

CentOS系统下GitLab的备份与恢复策略为了保障数据安全和可恢复性,CentOS上的GitLab提供了多种备份方法。本文将详细介绍几种常见的备份方法、配置参数以及恢复流程,帮助您建立完善的GitLab备份与恢复策略。一、手动备份利用gitlab-rakegitlab:backup:create命令即可执行手动备份。此命令会备份GitLab仓库、数据库、用户、用户组、密钥和权限等关键信息。默认备份文件存储于/var/opt/gitlab/backups目录,您可通过修改/etc/gitlab

docker原理详解 docker原理详解 Apr 14, 2025 pm 11:57 PM

Docker利用Linux内核特性,提供高效、隔离的应用运行环境。其工作原理如下:1. 镜像作为只读模板,包含运行应用所需的一切;2. 联合文件系统(UnionFS)层叠多个文件系统,只存储差异部分,节省空间并加快速度;3. 守护进程管理镜像和容器,客户端用于交互;4. Namespaces和cgroups实现容器隔离和资源限制;5. 多种网络模式支持容器互联。理解这些核心概念,才能更好地利用Docker。

docker desktop怎么用 docker desktop怎么用 Apr 15, 2025 am 11:45 AM

如何使用 Docker Desktop?Docker Desktop 是一款工具,用于在本地机器上运行 Docker 容器。其使用步骤包括:1. 安装 Docker Desktop;2. 启动 Docker Desktop;3. 创建 Docker 镜像(使用 Dockerfile);4. 构建 Docker 镜像(使用 docker build);5. 运行 Docker 容器(使用 docker run)。

centos怎么挂载硬盘 centos怎么挂载硬盘 Apr 14, 2025 pm 08:15 PM

CentOS硬盘挂载分为以下步骤:确定硬盘设备名(/dev/sdX);创建挂载点(建议使用/mnt/newdisk);执行mount命令(mount /dev/sdX1 /mnt/newdisk);编辑/etc/fstab文件添加永久挂载配置;卸载设备使用umount命令,确保没有进程使用设备。

centos停止维护后怎么办 centos停止维护后怎么办 Apr 14, 2025 pm 08:48 PM

CentOS 停止维护后,用户可以采取以下措施应对:选择兼容发行版:如 AlmaLinux、Rocky Linux、CentOS Stream。迁移到商业发行版:如 Red Hat Enterprise Linux、Oracle Linux。升级到 CentOS 9 Stream:滚动发行版,提供最新技术。选择其他 Linux 发行版:如 Ubuntu、Debian。评估容器、虚拟机或云平台等其他选项。

See all articles