Shell理論學習(二)

來源:互聯網
上載者:User

標籤:hello   world   

30.tee:讀取標準輸入,然後由標準輸出顯示,並把這些資料存放區在指定的檔案中

執行本命令,test.txt若已經存在,會被清空,若不存在則會建立一個新檔案,結束操作ctrl+D

[[email protected] ~]# tee test.txthello my world!hello my world![[email protected] ~]# cat test.txt hello my world!

-a以檔案追加的方式,把輸入的資料接在test.txt的檔案尾,並不會把test.txt清空

[[email protected] ~]# tee -a test.txt This is a zhuijia!This is a zhuijia![[email protected] ~]# cat test.txt hello my world!This is a zhuijia!

31.diff:比較兩個檔案的差異

[[email protected] test]# diff file4.txt ../test.txt 1,2c1,2< haha< hello myworld---> hello my world!> This is a zhuijia!

32.xargs:由標準輸入,安排要執行的命令和參數

尋找.txt的檔案,然後給xargs處理,-n 2 表示執行命令的參數至多兩個,也就是說:把找到的.txt檔案,兩個一組的方式交給diff去比較

[[email protected] ~]# find /root/test/ -name "*.txt"  | xargs -n 2 diff1,2d0< haha< hello myworld

33.可以把多個命令弄成一組,然後整組去執行

方法一:(命令1;命令2;命令3)

()會開啟一個子shell環境,來執行此括弧中的命令組

[[email protected] ~]# (cat test.txt;find /root/test/ -name "*.txt";date +%F)hello my world!This is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/file3.txt2015-01-09

方法二:{ 命令1;命令2;命令3; }

和第一種方法不同的是,此法是吧這些命令組在現行的shell中去執行,而非在子shell中執行

[[email protected] ~]# { cat test.txt;find /root/test/ -name "*.txt";date +%F; }hello my world!This is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/file3.txt2015-01-09

34.記錄命令的執行過程

有時候,我們需要把執行命令所產生的資訊記錄,以作為排錯參考,資料儲存之用

script[記錄檔]

如果不提供自訂的記錄檔,預設會把資料存放區到typescript這個檔案

執行script指令後,就可以開始操作各種命令,script會忠實的記錄下所有的輸出資訊.如果想要結束操作,執行exit,便可以離開script

[email protected] ~]# script /tmp/test.txtScript started, file is /tmp/test.txt[[email protected] ~]# ls /tmp/test.txt /tmp/test.txt[[email protected] ~]# { cat test.txt;find /root/test/ -name "*.txt";date +%F; }hello my world!This is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/file3.txt2015-01-09[[email protected] ~]# find /root/test/ -name "*.txt"  | xargs -n 2 diff1,2d0< haha< hello myworld[[email protected] ~]# exitexitScript done, file is /tmp/test.txt#查看日誌[email protected] ~]# head /tmp/test.txt Script started on 2015年01月09日 星期五 17時53分07秒[[email protected] ~]# { cat test.txt;find /root/test/ -name "*.txt";date +%F; }hello my world!This is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/file3.txt2015-01-09[[email protected] ~]# find /root/test/ -name "*.txt"  | xargs -n 2 diff

35.unset:

unset -v 變數名稱

選項-v表示要取消的是變數

unset -f 函數名稱

選項-f表示要取消的是函數

36.常用環境變數

  • PS1:主要提示符

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/5A/wKioL1TQ7F7yQ8X_AALsRCZXE58668.jpg" title="1.PNG" alt="wKioL1TQ7F7yQ8X_AALsRCZXE58668.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/5A/wKioL1TQ7PyxOoaeAAByTckp-Sk008.jpg" title="2.PNG" alt="wKioL1TQ7PyxOoaeAAByTckp-Sk008.jpg" />

本文出自 “Linux革命” 部落格,請務必保留此出處http://kaibinyuan.blog.51cto.com/7304008/1611304

Shell理論學習(二)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.