#重定向
输出重定向:
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
[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
原文:http://putongren.blog.51cto.com/9086263/1541272