欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

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

系統(tǒng) 3008 0

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

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

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

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

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

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

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、輸出重定向:> 覆蓋輸出。

  會覆蓋目標文件中的內容,容易發(fā)生錯誤。可以使用set -C禁止覆蓋已經(jīng)存在的文件。同理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、統(tǒng)計/usr/bin/目錄下的文件個數(shù)

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


      
      
        1479
      
    

2、取出當前系統(tǒng)上所有用戶的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文件中倒數(shù)第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開頭的文件,并統(tǒng)計其個數(shù)

      
        
          [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重定向


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲一区中文字幕 | 免费看的黄网站 | 一区二区三区日韩精品 | 奇米视频在线 | 日日爽夜夜| 亚洲 欧美 日韩 在线 香蕉 | 四虎免费久久影院 | ak福利视频 | 人人人人澡 | 第四色播日韩AV第一页 | 日韩成人在线观看 | 国产99久久精品一区二区永久免费 | 精品伊人久久久大香线蕉欧美 | 波多野吉衣 免费一区 | 亚洲欧美在线观看一区二区 | 日韩国产欧美在线观看 | 色www精品视频在线观看 | 国内精品伊人久久久久7777人 | 久草在线草a免费线看 | 久久影院一区二区三区 | 一级片视频免费观看 | 综合网婷婷 | 国产精品怕怕怕视频免费 | 精品免费久久久久欧美亚一区 | 欧美成人一区二区三区在线视频 | 亚洲成人精品久久 | 久久久久久亚洲 | 奇米影视777中文久久爱 | 91蝌蚪在线播放 | 国产a级一级久久毛片 | 亚洲自拍偷拍在线 | 爱爱视频天天干 | 久久伊人免费视频 | 日本欧美在线 | 久久精品国产99国产 | 欧美日韩中文视频 | 欧区一欧区二欧区三史无前例 | 九色国产 | 亚洲一级毛片中文字幕 | 亚洲精品乱码久久久久久蜜桃91 | 精品一区二区三区在线观看视频 |