zoukankan      html  css  js  c++  java
  • Linux重定向

    文件描述符-File Describtor

      stdin    0

      stdout    1

      stderr     2

    重定向标准输出-redirect stdout  >

    [keysystem@localhost redirect]$ echo hello>file1
    [keysystem@localhost redirect]$ echo world>file2
    [keysystem@localhost redirect]$ cat file1
    hello
    [keysystem@localhost redirect]$ cat file2
    world
    [keysystem@localhost redirect]$ cat file1 >file
    [keysystem@localhost redirect]$ cat file
    hello
    [keysystem@localhost redirect]$ cat file2 >file
    [keysystem@localhost redirect]$ cat file
    world
    [keysystem@localhost redirect]$ cat file
    file   file1  file2  
    [keysystem@localhost redirect]$ cat file1 >>file
    [keysystem@localhost redirect]$ cat file
    world
    hello
    [keysystem@localhost redirect]$ cat file1 file2 >file
    [keysystem@localhost redirect]$ cat file
    hello
    world
    [keysystem@localhost redirect]$ 

    重定向错误输出-redirect stdout  2>

    [keysystem@localhost redirect]$ ls shit
    ls: cannot access shit: No such file or directory
    [keysystem@localhost redirect]$ 
    [keysystem@localhost redirect]$ ls shit >out.put
    ls: cannot access shit: No such file or directory
    [keysystem@localhost redirect]$ 
    [keysystem@localhost redirect]$ cat out.put 
    [keysystem@localhost redirect]$ ls shit 2>out.put
    [keysystem@localhost redirect]$ 
    [keysystem@localhost redirect]$ cat out.put 
    ls: cannot access shit: No such file or directory
    [keysystem@localhost redirect]$ 

    重定向标准输入-redirect stdin  <

    [keysystem@localhost redirect]$ cat file
    hello
    world
    [keysystem@localhost redirect]$ 
    [keysystem@localhost redirect]$ grep world <file
    world
    [keysystem@localhost redirect]$ 

    管道命令-pipeline   | 

    [keysystem@localhost redirect]$ cat files.txt 
    d.txt
    a.txt
    f.html
    b.txt
    b.txt
    [keysystem@localhost redirect]$ cat files.txt |uniq
    d.txt
    a.txt
    f.html
    b.txt
    [keysystem@localhost redirect]$ cat files.txt |uniq|grep txt
    d.txt
    a.txt
    b.txt
    [keysystem@localhost redirect]$ cat files.txt |uniq|grep txt|sort
    a.txt
    b.txt
    d.txt
    [keysystem@localhost redirect]$
  • 相关阅读:
    祝师傅新婚快乐 :)
    NetBeans IDE 6.8 里程碑 2 已经可用!
    GRETA库在VS 2005环境下的编译经验
    祝师傅新婚快乐 :)
    NetBeans 时事通讯(刊号 # 74 Sep 30, 2009)
    忆父亲
    NetBeans 时事通讯(刊号 # 74 Sep 30, 2009)
    Miss Nev great app
    订阅我不会怀孕
    数据结构排序: 两路归并排序算法 子逸 博客园
  • 原文地址:https://www.cnblogs.com/alsodzy/p/7967546.html
Copyright © 2011-2022 走看看