Linux重定向
Posted 一个有点理想的码农
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux重定向相关的知识,希望对你有一定的参考价值。
文件描述符-File Describtor
stdin 0
stdout 1
stderr 2
重定向标准输出-redirect stdout >
[[email protected] redirect]$ echo hello>file1 [[email protected] redirect]$ echo world>file2 [[email protected] redirect]$ cat file1 hello [[email protected] redirect]$ cat file2 world [[email protected] redirect]$ cat file1 >file [[email protected] redirect]$ cat file hello [[email protected] redirect]$ cat file2 >file [[email protected] redirect]$ cat file world [[email protected] redirect]$ cat file file file1 file2 [[email protected] redirect]$ cat file1 >>file [[email protected] redirect]$ cat file world hello [[email protected] redirect]$ cat file1 file2 >file [[email protected] redirect]$ cat file hello world [[email protected] redirect]$
重定向错误输出-redirect stdout 2>
[[email protected] redirect]$ ls shit ls: cannot access shit: No such file or directory [[email protected] redirect]$ [[email protected] redirect]$ ls shit >out.put ls: cannot access shit: No such file or directory [[email protected] redirect]$ [[email protected] redirect]$ cat out.put [[email protected] redirect]$ ls shit 2>out.put [[email protected] redirect]$ [[email protected] redirect]$ cat out.put ls: cannot access shit: No such file or directory [[email protected] redirect]$
重定向标准输入-redirect stdin <
[[email protected] redirect]$ cat file hello world [[email protected] redirect]$ [[email protected] redirect]$ grep world <file world [[email protected] redirect]$
管道命令-pipeline |
[[email protected] redirect]$ cat files.txt d.txt a.txt f.html b.txt b.txt [[email protected] redirect]$ cat files.txt |uniq d.txt a.txt f.html b.txt [[email protected] redirect]$ cat files.txt |uniq|grep txt d.txt a.txt b.txt [[email protected] redirect]$ cat files.txt |uniq|grep txt|sort a.txt b.txt d.txt [[email protected] redirect]$
以上是关于Linux重定向的主要内容,如果未能解决你的问题,请参考以下文章