linux学习命令总结⑨

#重定向

输出重定向:

1>覆盖输出(1可省略)

[root@VM_168_102_centos tmp]# ls functions >shuchu
[root@VM_168_102_centos tmp]# cat shuchu 
functions
[root@VM_168_102_centos tmp]# ls fstab >shuchu
[root@VM_168_102_centos tmp]# cat shuchu 
fstab

1>>追加输出(1可省略)

[root@VM_168_102_centos tmp]# cat shuchu 
fstab
[root@VM_168_102_centos tmp]# ls functions >>shuchu
[root@VM_168_102_centos tmp]# cat shuchu 
fstab
functions

错误重定向:

2>:覆盖输出

[root@VM_168_102_centos tmp]# ls 
agent_cmd.sock  fstab      hellodirxyz  scripttest  test
ceshi           functions  rc.sysinit   shuchu
[root@VM_168_102_centos tmp]# ls fstab wanghan >shuchu
ls: cannot access wanghan: No such file or directory
[root@VM_168_102_centos tmp]# cat shuchu 
fstab
[root@VM_168_102_centos tmp]# ls fstab wanghan 2>shuchu
fstab
[root@VM_168_102_centos tmp]# cat shuchu 
ls: cannot access wanghan: No such file or directory

2>>:追加输出

[root@VM_168_102_centos tmp]# cat shuchu               
ls: cannot access wanghan: No such file or directory
[root@VM_168_102_centos tmp]# ls ssssdd wanghan 2>>shuchu
[root@VM_168_102_centos tmp]# cat shuchu 
ls: cannot access wanghan: No such file or directory
ls: cannot access ssssdd: No such file or directory
ls: cannot access wanghan: No such file or directory

同时重定标准输出和错误输出

[root@VM_168_102_centos tmp]# ls fstab wanghan >shuchu 2>cuowu[root@VM_168_102_centos tmp]# cat shuchu 
fstab
[root@VM_168_102_centos tmp]# cat cuowu 
ls: cannot access wanghan: No such file or directory
[root@VM_168_102_centos tmp]# ls fstab wanghan &>all       
[root@VM_168_102_centos tmp]# cat all
ls: cannot access wanghan: No such file or directory
fstab
[root@VM_168_102_centos tmp]# ls fstab wanghan >both 2>&1
[root@VM_168_102_centos tmp]# cat both 
ls: cannot access wanghan: No such file or directory
fstab

linux学习命令总结⑨,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。