1:linux中的输入输出
名称 说明 编号 默认
stdin 标准输入 0 键盘
stdout 标准输出 1 终端
stderr 标准错误 2 终端
2:基本输入输出
通过管道和重定向我们可以控制CLI的数据流
< 将标准输入(不包含错误信息)重定向到文件 (以覆盖的形式)
echo "hello world" < aa.file
<< 将标准输入重定向到文件(以追加的形式)
echo "hello world" << aa.file
2< 将标准错误重定向到文件
2<&1 将标准输入和标准错误结合在一起
< stdin
grep java > /etc/passwd 把passwd文件作为输入命令。
3:管道 将一个命令的标准输出作为另外一个命令的标准输入
ls -l | grep java 从 列出来的目录中查找关键字
网上找了一些管道使用的列子 大家可以看下
[chengmo@centos5
shell]$
cat
test
.sh
|
grep
-n
'echo'
5:
echo
"very
good!"
;
7:
echo
"good!"
;
9:
echo
"pass!"
;
11:
echo
"no
pass!"
;
#读出test.sh文件内容,通过管道转发给grep
作为输入内容
[chengmo@centos5
shell]$
cat
test
.sh
test1.sh |
grep
-n
'echo'
cat
:
test1.sh: 没有那个文件或目录
5:
echo
"very
good!"
;
7:
echo
"good!"
;
9:
echo
"pass!"
;
11:
echo
"no
pass!"
;
#cat
test1.sh不存在,错误输出打印到屏幕,正确输出通过管道发送给grep
[chengmo@centos5
shell]$
cat
test
.sh
test1.sh 2>
/dev/null
|
grep
-n
'echo'
5:
echo
"very
good!"
;
7:
echo
"good!"
;
9:
echo
"pass!"
;
11:
echo
"no
pass!"
;
#将test1.sh
没有找到错误输出重定向输出给/dev/null 文件,正确输出通过管道发送给grep
[chengmo@centos5
shell]$
cat
test
.sh
|
ls
catfile
httprequest.txt secure
test
testfdread.sh
testpipe.sh testsh.sh testwhile2.sh
envcron.txt
python sh testcase.sh testfor2.sh testselect.sh
test
.txt
text.txt
env
.txt
release sms testcronenv.sh testfor.sh
test
.sh
testwhile1.sh
#读取test.sh内容,通过管道发送给ls命令,由于ls
不支持标准输入,因此数据被丢弃