文本查看類命令
阿新 • • 發佈:2018-03-31
進行 正則 大小 file markdown 空白行 uil bin 等待
顯示匹配到的行號
文本查看類命令:cat,tac,more,less,head,tail,tailf,grep,egrep
cat
將文本連接起來顯示在標準輸出
-n
顯示行號
-s
將多個連續的空白行(不能有空格或制表符)合並顯示為一個空白行,文本連接處也可合並
-e
相當於-vE
-E
--show-ends
顯示結束符號$
-v
顯示非打印符,沒弄明白這個選項怎麽使用
[zyb@ZYB ~]$ cat -ne test_file1 1 This is in test_file1.$ 2 $ 3 $ 4 $ [zyb@ZYB ~]$ cat -ne test_file2 1 $ 2 This is in test_file2$ 3 $ 4 $ 5 $ 6 $ [zyb@ZYB ~]$ cat -ne test_file1 test_file2 1 This is in test_file1.$ 2 $ 3 $ 4 $ 5 $ 6 This is in test_file2$ 7 $ 8 $ 9 $ 10 $ [zyb@ZYB ~]$ cat -nes test_file1 test_file2 1 This is in test_file1.$ 2 $ 3 $ 4 This is in test_file2$ 5 $ 6 $ 7 $ 8 $
tac
逆序顯示文件
more
只支持向後翻,翻到結尾處退出,默認一次翻一屏,空格翻屏
-Num
定義一屏為Num行
less
支持前後翻行,翻到末尾處不自動退出,j
k
操作
head
顯示前多少行,默認前十行
-Num
顯示前Num行
tail
顯示後多少行,默認顯示後十行,但是前後順序不便
-Num
顯示後Num行
-f
顯示完一個文件後不退出,等待這個文件其他數據流輸入,並顯示出來,常用於手動監視日誌文件
[zyb@ZYB ~]$ tail -3 -f /etc/passwd tail: option used in invalid context -- 3 [zyb@ZYB ~]$ tail -n3 -f /etc/passwd zyb:x:1000:1000:張永博:/home/zyb:/bin/bash zpy:x:1001:1001:張飄揚:/home/zpy:/bin/bash mockbuild:x:1002:1002::/home/mockbuild:/bin/bash
tailf
顯示後多少行並等待這個文件的其他數據流的輸入,默認後十行
-Num
顯示後Num行並等待其他數據流輸入
grep:(global search regular express and print out the line),根據用戶所指定文本模式對目標文件進行逐行搜索,並顯示匹配行
格式:grep [option] `Pattern` file,... `Pattern`
其中Pattern單雙引號取決於替換與否
選項:
--color
指定顏色
-v
反向匹配,顯示不能被模式匹配到的行
-o
僅顯示被模式匹配到的字符串
-i
不區分大小寫
-n
-A #
還顯示模式下面的#行-B #
還顯示模式上面的#行-C #
還顯示模式上面的#行-E
支持擴展正則表達式
egrep適用於拓展正則表達式
文本查看類命令