美文网首页
linux 重定向与管道

linux 重定向与管道

作者: 小小机器人 | 来源:发表于2016-12-01 21:22 被阅读57次
    一:重定向
    1. 输入重定向(真不知道有什么卵用)
    2. 输出重定向

    ‘>(覆盖)’ :把原本输出到屏幕的信息输出到其他地方

    [xxjqr@localhost Desktop]$ cat test2.txt 
    this is test2 file
    [xxjqr@localhost Desktop]$ touch test.txt
    [xxjqr@localhost Desktop]$ cat test2.txt > test.txt 
    [xxjqr@localhost Desktop]$ cat test.txt 
    this is test2 file
    [xxjqr@localhost Desktop]$ 
    

    '>>(追加)'

    二:管道

    管道其实就是一个连接符,把上一条命令的输出当作此条命令的输入

    [xxjqr@localhost Desktop]$ cat test.txt 
    This is first line
    This is second line
    This is third line
    [xxjqr@localhost Desktop]$ cat test.txt | grep third
    This is third line
    [xxjqr@localhost Desktop]$ 
    
    

    管道实例

    [root@localhost Desktop]# cat /etc/passwd | grep root #查看是否存在指定账户
    root:x:0:0:root:/root:/bin/bash
    operator:x:11:0:operator:/root:/sbin/nologin
    [root@localhost Desktop]# dmesg | grep eth0 #查看第一块网卡信息
    e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:0c:29:a1:49:1e
    e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection
    ADDRCONF(NETDEV_UP): eth0: link is not ready
    8021q: adding VLAN 0 to HW filter on device eth0
    e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
    ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
    eth0: no IPv6 routers present
    e1000: eth0 NIC Link is Down
    e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
    [root@localhost Desktop]# rpm -qa | grep httpd #查看是否安装了apache软件
    httpd-2.2.15-53.el6.centos.x86_64
    httpd-tools-2.2.15-53.el6.centos.x86_64
    

    相关文章

      网友评论

          本文标题:linux 重定向与管道

          本文链接:https://www.haomeiwen.com/subject/ixuapttx.html