亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

《鳥哥的Linux私房菜》學習筆記(6)——管道及

系統 2899 0

一、標準I/O ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

標準輸入: 也可以叫STDIN,用0來標識,通常是鍵盤

標準輸出: 也可以叫STDOUT,用1來標識,通常是顯示器

標準錯誤輸出 :STDERR,用2來標識,通常是顯示器

二、I/0重定向 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

I/O重定向是指改變數據的輸入或輸出來源。

1、輸入重定向:<

      
        
          [root@hao ~]#
        
      
      
        tr
      
      
        '
      
      
        a-z
      
      
        '
      
      
        '
      
      
        A-Z
      
      
        '
      
       < /etc/
      
        fstab



#

# 
      
      /ETC/
      
        FSTAB

# CREATED BY ANACONDA ON SAT JUL 
      
      
        26
      
      
        20
      
      :
      
        12
      
      :
      
        53
      
      
        2014
      
      
        

#

...
      
    

2、在此處生成文檔:<< 通常和EOF或END一起使用

      
        
          [root@hao ~]#
        
      
      
        cat
      
       <<
      
         END


      
      >
      
         the first line


      
      >
      
         second


      
      >
      
         end


      
      >
      
         END

the first line

second

end
        
[root@hao ~]# cat >> /tmp/myfile.txt << EOF > the first line > second > EOF [root@hao ~]# cat /tmp/ myfile.txt the first line second

3、輸出重定向:> 覆蓋輸出。

  會覆蓋目標文件中的內容,容易發生錯誤??梢允褂胹et -C禁止覆蓋已經存在的文件。同理set +C則可以關閉上述功能。默認情況下是可以覆蓋,當然在set -C 關閉覆蓋輸出功能情況下,如果要強制覆蓋輸出,則可以使用>|來強制覆蓋輸出。

      set -C
    

4、輸出重定向:>>追加輸出

      
        
          [root@hao tmp]#
        
      
      
        ls
      
       /
      
        var

account  crash  db     games  lib    lock  mail  opt       run    tmp  yp

cache    cvs    empty  gdm    local  log   nis   preserve  spool  www


        
          
            [root@hao tmp]# 
          
        
      
      
        ls
      
       /var >/tmp/
      
        var.out


        
          
            [root@hao tmp]#
          
        
      
      
        cat
      
       /tmp/
      
        var.out

account

cache

...
      
    

5、重定向錯誤輸出:2>,如果不是錯誤輸出,則2>相當于>

6、追加方式重定向錯誤輸出:2>>

      
        
          [root@hao ~]#
        
      
      
        ls
      
       /varr > /tmp/
      
        var2.out


      
      
        ls
      
      : cannot access /varr: No such 
      
        file
      
      
         or directory


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        ls
      
       /varr 
      
        2
      
      > /tmp/
      
        var2.out


        
          
            [root@hao
          
        
      
      ~]# 
      
        cat
      
       /tmp/
      
        var2.out


      
      
        ls
      
      : cannot access /varr: No such 
      
        file
      
      
         or directory


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        ls
      
       /var 
      
        2
      
      > /tmp/
      
        var2.out

account  crash  db     games  lib    lock  mail  opt       run    tmp  yp

cache    cvs    empty  gdm    local  log   nis   preserve  spool  www
      
    

7、若為標準輸出,則輸出到某一個文件,若為錯誤輸出,則重定向到另一個文件

      
        
          [root@hao ~]#
        
      
      
        ls
      
       /var > /tmp/var2.out 
      
        2
      
      >/tmp/
      
        err.out 


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        cat
      
       /tmp/
      
        var2.out

account

cache

crash

...

[root@hao 
      
      ~]# 
      
        cat
      
       /tmp/err.out
    

8、重定向標準輸出和錯誤輸出至同一個文件:&>

      
        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        ls
      
       /var# &> /tmp/
      
        var3.out


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        cat
      
       /tmp/
      
        var3.out


      
      
        ls
      
      : cannot access /var#: No such 
      
        file
      
      
         or directory


        
          
            [root@hao
          
        
      
      ~]# 
      
        ls
      
       /var &> /tmp/
      
        var3.out


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        cat
      
       /tmp/
      
        var3.out

account

cache

...
      
    

三、管道 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

管道:把前一個命令的輸出,作為后一個命令的輸入,以此類推至多個命令。

      
        
          [root@hao ~]#
        
      
      
        echo
      
      
        '
      
      
        hello world
      
      
        '
      
       | 
      
        tr
      
      
        '
      
      
        a-z
      
      
        '
      
      
        '
      
      
        A-Z
      
      
        '
      
      
        

HELLO WORLD

[root@hao 
      
      ~]# 
      
        cut
      
       -d: -f1 /etc/
      
        passwd
      
       |
      
        sort
      
      
        

abrt

adm

apache

...


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        cut
      
       -d: -f3 /etc/
      
        passwd
      
       |
      
        sort
      
       -
      
        n


      
      
        0
      
      
        1
      
      
        2
      
      
        3
      
      
        4
      
      
        5
      
      
        6
      
      
        7
      
      
        8
      
      
        

...


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        cut
      
       -d: -f1 /etc/
      
        passwd
      
       |
      
        sort
      
      |
      
        tr
      
      
        '
      
      
        a-z
      
      
        '
      
      
        '
      
      
        A-Z
      
      
        '
      
      
        

ABRT

ADM

APACHE

AVAHI
      
      -
      
        AUTOIPD

BIN

...
      
    

四、tee命令,輸出到文件中,且輸出到屏幕上 ? ? ? ? ? ? ? ?

      
        
          [root@hao ~]#
        
      
      
        echo
      
      
        '
      
      
        hello world
      
      
        '
      
       | 
      
        tee
      
       /tmp/
      
        hello.out

hello world


        
          
            [root@hao 
          
        
      
      
        
          ~]#
        
      
      
        cat
      
       /tmp/
      
        hello.out

hello world
      
    

五、練習 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

1、統計/usr/bin/目錄下的文件個數

      [root@hao ~]# 
      
        ls
      
       /usr/bin | 
      
        wc
      
       -
      
        l


      
      
        1479
      
    

2、取出當前系統上所有用戶的shell,要求每種shell只顯示以此,并且按順序顯示

      [root@hao ~]# 
      
        cut
      
       -d: -f7 /etc/
      
        passwd
      
      |
      
        sort
      
       -
      
        u


      
      /bin/
      
        bash


      
      /bin/
      
        sync
      
      

/bin/
      
        tcsh


      
      /sbin/
      
        halt


      
      /sbin/
      
        nologin


      
      /sbin/shutdown
    

3、顯示/var/log目錄下每個文件的內容類型

      [root@hao ~]# 
      
        file
      
       /var/log
      
        /*
      
      
        

/var/log/anaconda.ifcfg.log:   ASCII text

/var/log/anaconda.log:         UTF-8 Unicode English text

/var/log/anaconda.program.log: ASCII English text, with very long lines, with overstriking

/var/log/anaconda.storage.log: UTF-8 Unicode C++ program text, with very long lines
        
...

4、取出/etc/inittab文件的第六行

      
        
          [root@hao log]#
        
      
      
        head
      
       -
      
        6
      
       /etc/inittab |
      
        tail
      
       -
      
        1
      
      
        

#
      
    

5、取出/etc/passwd文件中倒數第9個用戶的用戶名和shell,顯示到屏幕上并將其保存至/tmp/users文件中

      
        
          [root@hao log]#
        
      
      
        tail
      
       -
      
        9
      
       /etc/
      
        passwd
      
       |
      
        head
      
       -
      
        1
      
      |
      
        cut
      
       -d: -f1,
      
        7
      
      |
      
        tee
      
       /tmp/
      
        users

tcpdump:
      
      /sbin/nologin
    

6、顯示/etc目錄下所有一pa開頭的文件,并統計其個數

      
        
          [root@hao log]#
        
      
      
        ls
      
       -d /etc/pa*|
      
        wc
      
       -
      
        l


      
      
        5
      
    

7、不使用文本編輯器,將alias cls=clear 一行內容添加至當前用戶的.bashrc文件中。

      
        
          [root@hao log]#
        
      
      
        echo
      
      
        "
      
      
        alias cls=clear
      
      
        "
      
       >> ~/.bashrc
    

?

《鳥哥的Linux私房菜》學習筆記(6)——管道及IO重定向


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!??!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 最新国产精品久久精品 | 免费亚洲视频 | 黄色a∨| 手机在线看片国产日韩生活片 | 欧美一级高清片欧美国产欧美 | 亚洲国产精品一区 | 日韩精品亚洲精品485页 | 日日躁夜夜躁狠狠天天 | 午夜精品久久久久久久99 | 欧美日韩视频在线 | 久久99精品福利久久久 | 国产精品夜色视频一级区 | 四虎影视永久免费观看 | 久久精品亚洲热综合一本奇米 | 伊人这里只有精品 | 久久国产精品国产自线拍免费 | 国产精品分类视频分类一区 | 四虎影视永久免费观看地址 | 久久久亚洲欧洲国产 | 来自深渊在线观看 | 亚洲社区在线 | 国产娱乐凹凸视觉盛宴在线视频 | 欧美第一页在线观看 | 大尺度福利视频在线观看网址 | 97网站| 久久久久久久尹人综合网亚洲 | 黑人日美女 | 国产综合影院 | 美女一级毛片免费不卡视频 | 国产在线精品二区赵丽颖 | 国产欧美精品一区二区三区 | 久久66热re国产毛片基地 | 一区二区不卡久久精品 | 精品久久久久久久久久香蕉 | 国产亚洲精品2021自在线 | 久久ri精品高清一区二区三区 | 一本色道久久88加勒比—综合 | 亚洲视频福利 | 天天干夜夜做 | 成人免费精品视频 | 午夜欧美精品久久久久久久 |