查看檔案內容
1. cat
用法:cat [選項]...[檔案]...
選項:
-n 顯示行號,包括空白行
-b 顯示行號,空白行不顯示行號
eg:
[root@qll ~]# cat /etc/passwd
[root@qll ~]# cat -n /etc/passwd
[root@qll ~]# cat -b /etc/passwd
2. more
more命令和cat的功能一樣都是查看檔案里的內容,但有所不同的是more可以按頁來查看檔案的內容,還支持直接跳轉行等功能,
Enter鍵:向下n行,需要定義,默認為1行
空格鍵:向下滾動一屏
Ctrl+B:回傳上一屏
= 輸出當前行的行號
V 呼叫vi編輯器
!命令 呼叫Shell,并執行命令
q 退出more
eg:
[root@qll ~]# more /var/log/messages
3. less
描述:分頁查看檔案內容,
操作:
空格(下一頁)
方向鍵(上下回翻)
q鍵(退出查看)
eg:
[root@qll ~]# less /var/log/mingongge.log
4. head
用法:head [選項]...[檔案]...
選項:
-c nK 顯示檔案前nKB的內容,
-n 顯示檔案前n行的內容,
eg:
[root@qll ~]# head -c 2k /var/log/messages#查看檔案的前2KB的內容
[root@qll ~]# head -n 15 /var/log/messages#查看檔案的前15行的內容
5. tail
用法:tail [選項]...[檔案]...
選項:
-c nK 顯示檔案末尾nKB的內容,
-n 顯示檔案末尾n行的內容,
-f 動態顯示檔案內容,常用于查看日志,按 Ctrl+C 組合鍵退出,
eg:
[root@qll ~]# tail -c 2KB /var/log/messages#查看檔案末尾2KB的內容
[root@qll ~]# tail -n 15 /var/log/messages#查看檔案末尾15行的內容
[root@qll ~]# tail -f /var/log/messages#實時動態查看檔案內容
6. grep
用法:grep [選項] 匹配模式 [檔案]...
常用選項:
-i 忽略大小寫,
-v 取反匹配
eg:
[root@qll ~]# grep root /etc/passwd#在passwd檔案中過濾出包含root的行,
[root@qll ~]# grep -i ROOT /etc/passwd#過濾出包含ROOT的行(不區分大小寫)
[root@qll ~]# grep -v root /etc/passwd#過濾出不包含root的行,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/263421.html
標籤:其他
下一篇:高頻面試題:Redis的使用場景
