7.1 管道、重定向

1.shell命令行 的数据流定义
STDIN : 标准输入(键盘) 编号0
STDOUT: 标准输出(终端) 编号1
STDERR: 标准输出(终端) 编号2

2.重定向
syntax: >
desc: 将STDOUT重定向到文件(覆盖)
eg: echo "hellow" > outfile
ls > outfile

syntax: >>
desc: 将STDOUT重定向到文件(追加)
eg: echo "hellow" >> outfile
date >> outfile

syntax: 2>
desc: 将STDERR重定向到文件(覆盖)
eg:  ls nothere 2> errorfile

syntax: 2>$1
desc: 将STDOUT 和 STDERR重定向到文件(覆盖)
eg: ls nothere 2>&1 alloutput

syntax: <
desc: 重定向STDIN
eg: grep linuxcast < /etc/passwd

3.管道
syntax: |
desc 将一个命令的stdout 作为另一个命令的 STDIN
eg: ls -l | grep linuxcast
find /-usr linuxcast | grep video


猜你喜欢

转载自oracle-api.iteye.com/blog/2171810