重定向与管道

输出重定向0:
ls -l /tmp > /tmp.msg
date >> /tmp.msg


输入重定向1:
wall < /etc/motd


错误输出重定向2:
cp -R /usr /backup/usr/bak 2> /bak.error


lee@lee-pc:~/test$ ls
a.hard      a.soft   tartest.tar.gz  ziptestfile
a.hard.bz2  tartest  testfile        ziptestfile.zip
lee@lee-pc:~/test$ ls /testfile
ls: 无法访问/testfile: 没有那个文件或目录
lee@lee-pc:~/test$ ls /testfile 2> ls.err
lee@lee-pc:~/test$ ls
a.hard      a.soft  tartest         testfile     ziptestfile.zip
a.hard.bz2  ls.err  tartest.tar.gz  ziptestfile
lee@lee-pc:~/test$ cat ls.err 
ls: 无法访问/testfile: 没有那个文件或目录
lee@lee-pc:~/test$ 


管道:将一个命令的输出传送给另一个命令,作为另一个命令的输入。
命令1|命令2|命令3......|命令n
ls -l /etc |more
lee@lee-pc:~/test$ ls -l /etc | more
总用量 1248
drwxr-xr-x   3 root root     4096 2013-09-30 11:46 acpi
-rw-r--r--   1 root root     2981 2011-10-12 22:27 adduser.conf
-rw-r--r--   1 root root       10 2012-05-09 00:18 adjtime
drwxr-xr-x   2 root root    12288 2013-10-10 15:46 alternatives
-rw-r--r--   1 root root      395 2010-06-20 16:11 anacrontab
-rw-r--r--   1 root root      112 2007-06-22 21:12 apg.conf


lee@lee-pc:~/test$ ls -l /etc | grep cron
-rw-r--r--   1 root root      395 2010-06-20 16:11 anacrontab
drwxr-xr-x   2 root root     4096 2011-10-12 22:31 cron.d
drwxr-xr-x   2 root root     4096 2013-09-30 11:46 cron.daily
drwxr-xr-x   2 root root     4096 2011-10-12 22:27 cron.hourly
drwxr-xr-x   2 root root     4096 2011-10-12 22:31 cron.monthly
-rw-r--r--   1 root root      724 2011-09-20 08:07 crontab
drwxr-xr-x   2 root root     4096 2011-10-12 22:31 cron.weekly
lee@lee-pc:~/test$ 


lee@lee-pc:~/test$ ls -l /etc | grep cron | wc -l
7
lee@lee-pc:~/test$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值