码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 之 特殊字符理解(第六章)

时间:2018-05-06 10:32:07      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:linux特殊字符

特殊符号:

输入重定向:把前面输出的东西输入到后边的文件中,会清除文件原有内容。
例子:
[root@localhost kang]# echo ‘hello world‘ > test.txt
[root@localhost kang]# cat test.txt
hello world

> 追加输出重定向:把前面输出的东西追加到后边的文件尾部,不会清除文件原有内容。
例子:
[root@localhost kang]# cat test.txt
hello world
ming kang

< 输入重定向:输入重定向用于改变命令的输入,后面指定输入内容,前面跟文件名。
例子:
[root@localhost kang]# xargs -n 1 < test.txt
hello
world
ming
kang

<< 追加输入重定向:后跟字符串,用来表示“输入结束”,也可用ctrl+d来结束输入
[root@localhost kang]# cat >>test.txt<<eof

you are welcome
eof
[root@localhost kang]# cat test.txt
hello world
ming kang
you are welcome

2> 错误重定向:把错误信息输入到后边的文件中,会删除文件原有的内容。
例子:
[root@localhost kang]# echb ‘error‘ 2> test.txt
[root@localhost kang]# cat test.txt
-bash: echb: command not found

2>> 错误追加重定向:把错误信息追加到后边的文件中,不会删除文件原有内容。
[root@localhost kang]# eco ‘test‘ 2>> test.txt
[root@localhost kang]# cat test.txt
-bash: echb: command not found
-bash: eco: command not found

把正确与错误的信息,分别输入不同的文件方法:
[root@localhost kang]# echo ‘hello world‘ >ok.txt 2>error.txt
[root@localhost kang]# cat ok.txt
hello world

把正确与错误的信息,输入相同的文件:
[root@localhost kang]# ech ‘error‘ >>ok.txt 2>&1
[root@localhost kang]# cat ok.txt
hello world
-bash: ech: command not found

Linux 之 特殊字符理解(第六章)

标签:linux特殊字符

原文地址:http://blog.51cto.com/12965094/2113060

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!