重定向和追加
输出重定向
格式: 命令 操作符号 文件名
参数:
1、 1> 或 > 把STDOUT重定向到文件 2、 2> 把STDERR重定向到文件 3、 &> 把标准输出和错误都重定向 4、 >& 和上面功能一样,建议使用上面方式 举例 :把主机名写入1.txtroot@centos7 test]# honstname > 1.txt
[root@centos7 test]# cat 1.txt
centos7.lixiangshuai
[root@centos7 test]# cat 1.txt
centos7.lixiangshuai
[root@centos7 test]# ls >> 1.txt
[root@centos7 test]# cat 1.txt
centos7.lixiangshuai
1.taxt
1.txt
2.txt
3.txt
f1.img
f2.img
f3.img
fi.img
[root@centos7 test]#
输入重定向
格式:
COMMAND 0< FILE COMMAND < FILE举例
[root@centos7 test]# ls < 2.txt
1.taxt 1.txt 2.txt 3.txt f1.img f2.img f3.img fi.img
[root@centos7 test]# cat 2.txt
[root@centos7 test]#
[root@centos7 test]# ls < 2.txt > 1.txt
[root@centos7 test]# cat 1.txt
1.taxt
1.txt
2.txt
3.txt
f1.img
f2.img
f3.img
fi.img
[root@centos7 test]#
举例2:
[root@centos7 test]# cat 2.txt
abc
[root@centos7 test]# tr 'a-z' 'A-Z' < 2.txt
ABC
[root@centos7 test]# cat 2.txt
abc
[root@centos7 test]#