首页 > 系统服务 > 详细

shell之路【第四篇】输入输出重定向

时间:2016-02-03 23:31:37      阅读:486      评论:0      收藏:0      [点我收藏+]

输出重定向

命令输出重定向的语法为:

command > file 或 command >> file

 这样,输出到显示器的内容就可以被重定向到文件。果不希望文件内容被覆盖,可以使用 >> 追加到文件末尾

技术分享
[root@hy ~]# who
root     tty1         2015-09-03 16:21
root     pts/3        2015-09-03 19:09 (192.168.11.1)
[root@hy ~]# who > output.txt
[root@hy ~]# cat output.txt
root     tty1         2015-09-03 16:21
root     pts/3        2015-09-03 19:09 (192.168.11.1)
View Code

输入重定向(<可省略)

command < file 
技术分享
[root@hy ~]# wc -l output.txt
2 output.txt
[root@hy ~]# wc -l < output.txt
2
View Code
技术分享
[root@hy ~]# grep tty output.txt
root     tty1         2015-09-03 16:21
[root@hy ~]# grep tty < output.txt
root     tty1         2015-09-03 16:21
View Code

 

 

shell之路【第四篇】输入输出重定向

原文:http://www.cnblogs.com/hyit/p/5180785.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!