grep bc test grep "bc" test grep 'bc' test
-i, --ignore-case 忽略大小寫 -n, --line-number print line number with output lines -v, --invert-match select non-matching lines 顯示不匹配的行 -h, --no-filename suppress the prefixing filename on output查詢多文件時不顯示文件名 -l, --files-with-matches print only names of FILEs containing matches查詢多文件時只顯示文件名 grep select * , 列出當前目錄下全部包含select 字樣的文件名及含有select字樣的行。 grep -h select * , 和上一條類似,但不顯示文件名稱。 grep -l select * , 和第一條類似,但只顯示文件名。
egrep 是擴充功能的grep egrep ‘2|5’ 1.txt ,列出含有2或者5的行 egrep '12(@|3)' test 列出含有12且後面緊跟@或3的行
從標準輸入中替換、縮減和/或刪除字符,並將結果寫到標準輸出。 html
-s, --squeeze-repeats 若是匹配於SET1 的字符在輸入序列中存在連續的重複,在替換時會被統一縮爲一個字符的長度 tr test '12' '45' 將文件中的12替換爲45 cat test |tr '[a-z]' '[A-Z]' 將文件中的小寫所有替換爲大寫 tr ' ' '\n' <test 把test文件中的全部空格替換爲換行 tr -s ' ' ' ' <test 把test文件中每行中連續出現的空格替換爲一個空格
sort [選項]... --files0-from=F linux
串聯排序全部指定文件並將結果寫到標準輸出。 shell
-c, --check, --check=diagnose-first 檢查輸入是否已排序,若已有序則不進行操做 -r, --reverse 逆序輸出排序結果 -n, --numeric-sort 根據字符串數值比較 -k, --key=位置1[,位置2] 在位置1 開始一個key,在位置2 終止(默認爲行尾) -u, --unique 配合-c,嚴格校驗排序;不配合-c,則只輸出一次排序結果
-c, --count 在每行前加上表示相應行目出現次數的前綴編號 -d, --repeated 只輸出重複的行
cut -d" " -f1 test 以空格爲分割符,並輸出第一列 last | cut -c1-20 //將 last 以後的數據,每一行的 1-20 個字符取出來
last |tail |tee last.list | cut -d " " -f1 將last的最後10行寫進last。last文件並接着處理並輸出在屏幕。
-l, --lines=數值 指定每一個輸出文件有多少行 -C, --line-bytes=大小 指定每一個輸出文件裏最大行字節大小
[guo@guo ~]$ type vim vim is hashed (/usr/bin/vim) [guo@guo ~]$ type perl perl is /usr/bin/perl
find /home/guo/ -name test找出文件夾guo中的test文件 find / -name 「*apple* -print find /home –name 「[!abc]」 find /home –name 「?[1-9]」 find / -type d(f b c l p) find / -mtime -5 查找最後修改小於5天的文件 -mtime 文件修改時間//vi、echo修改文件會改變此文件時間 -atime 文件訪問時間//用cat、vi查看會改變此文件時間 -ctime 文件改變時間// vi 、echo修改文件、chmod、chown會改變此文件時間 stat fileanme 查看以上3個時間
xargs從標準輸入中接受單詞列表的命令,並把這些單詞做爲參數傳遞給指定的命令 編程
ls |xargs rm//把ls列出的內容再經過rm刪除 能夠每次刪除一部分文件 ls |xargs –n 2 rm ls | xargs –n 2 echo 「==>」 有時目錄裏文件太多了不能使用rm *刪除這時 ls | grep ‘^abc’ |xargs –n 20 rm
bc命令:進行算術運算,但不限於整數運算 scale=4 //表示計算結果保留4位小數 bc還能夠用在shell變量賦值中 ABC=`echo 「scale=4;8/3」 | bc` echo $ABC腳本編程 1.1.1.1 www.baidu.com 2.2.2.2 www.baidu.com 3.3.3.3. www.sina.com.cn 2.2.2.2 www.chinauxin.net 2.2.2.2 www.51cto.com 1.1.1.1 www.linuxtone.org 輸出 2.2.2.2 www.baidu.com,www.chinauxin.net,www.51cto.com 1.1.1.1 www.baidu.com,www.linuxtone.org 3.3.3.3. www.sina.com.cn awk '{a[$1]=a[$1]" "$2}END{for(i in a)print i,a[i]}' file 建立html文件 ::cat 運維必備.html |sed -e '/^$/d'|sed -n '2,$ s/^/\<br\>/p' |sed 's/$/\<\/br\>/' >a.html 內核、Shell、文件系統這三個部分構成了linux系統 合併兩個文件 paste 1 2|awk '{if($1 ~$2) print $1 ;else print $0}' a=`date +"%Y-%m-%d %H : %M : %S" -d "5 min ago"`