標籤: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.常用環境變數
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理論學習(二)