shell-重定向

2019-08-13  本文已影响0人  哆来咪发都不会
>: 重写(正确信息)
>>: 追加(正确信息)
2>: 重写(错误信息)
2>>: 追加(错误信息)
&>: 重写(全部信息)
&>>: 追加(全部信息)
实例
[root@localhost wang]# ls
123.txt  1.txt  23.txt  2.txt  3.txt  a.txt  A.txt
[root@localhost wang]# ls 123.txt >test.txt
[root@localhost wang]# cat test.txt 
123.txt
[root@localhost wang]# ls 2.txt >test.txt 
[root@localhost wang]# cat test.txt 
2.txt
[root@localhost wang]# ls a.txt >>test.txt 
[root@localhost wang]# cat test.txt 
2.txt
a.txt
[root@localhost wang]# ls h.txt 2>test.txt 
[root@localhost wang]# cat test.txt 
ls: 无法访问h.txt: 没有那个文件或目录
[root@localhost wang]# ls hahah.txt 2>>test.txt 
[root@localhost wang]# cat test.txt 
ls: 无法访问h.txt: 没有那个文件或目录
ls: 无法访问hahah.txt: 没有那个文件或目录
[root@localhost wang]# ls a.txt h.txt 1.txt &> test.txt 
[root@localhost wang]# cat test.txt 
ls: 无法访问h.txt: 没有那个文件或目录
1.txt
a.txt
[root@localhost wang]# 
上一篇 下一篇

猜你喜欢

热点阅读