重定向和管道操作

 
Redirection Operation
重定向和管道操作
 
All Shell
< file    > file    >> file
Cmd1 | cmd2
0 stdin, 1 stdout, 2 stderr
 
 
sh, ksh
0< file    1> file    2> file    1>> file    2>> file
<&m    >&m    m>&n, m,n is file descriptor
<&-, close standard input
>&-, close standard output
m<&-    m>&-, close file descriptor m
 
examples:
grep “John” 0< tempfile
ls –l foo 2> error.log
cat lab1 lab2 lab3 1> cat.output 2> cat.err
cat lab1 lab2 lab3 1> cat.output.err 2>&1
    pay attention to the redirection instruction order
    cat lab1 lab2 lab3 2>&1 1> cat.output.err
ls –l foo 1>> output.dat 2>> error.log
 
 
ksh
set –o noclobber, set noclobber to prevent overwritting files accidently.
set +o noclobber
>| file, ignore noclobber and assign stdout to ‘file’
>>| file, ignore noclobber and append stdout to ‘file’
 
 
csh
>& file, output and error redirection
>! file, ignore noclobber and assign stdout to ‘file’
>>! file, ignore noclobber and append stdout to ‘file’,
          if file does not exit, create it.
>>&! file, ignore noclobber, append stdout and stderr to ‘file’
cmd1 |& cmd2, connect stdout and stderr of cmd1 to stdin of cmd2
(cmd>/dev/tty)>&file, redirect stderr of cmd to ‘file’
set noclobber
unset noclobber
 
/dev/tty
/dev/null
抛弃输出数据, 如 $ echo "hello" > /dev/null
获取空文件,如 $ cat /dev/null > messages
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值