Linux 命令 more
是一個強大的工具,它允許使用者在終端中一屏一屏地檢視文字檔案。對於經常處理大型文字檔案的人來說,這是一個必不可少的命令。通過將內容分解成易於管理的小塊,more
命令增強了可讀性和導航性,使分析和理解檔案中的資料變得更容易。
與 more
命令類似,less
命令也提供了額外的靈活性和功能,例如向後導航。這兩種命令都常用於檢視日誌檔案、配置檔案和 Linux 環境中的其他文字檔案。對於那些希望結合命令完成更復雜任務的人來說,more
命令可以與 grep
等工具一起使用,以搜尋檔案中的特定模式。
如何使用 more
1. 檢視檔案
語法: more [filename]
說明:逐屏顯示檔案內容。
示例: more myfile.txt
輸出:
This is line 1 This is line 2 --More--(10%)
輸出結果顯示了 myfile.txt
的前幾行,並表明已顯示檔案的 10%。按空格鍵將顯示下一屏內容。
2. 檢視多個檔案
語法: more file1 file2 ...
說明:按順序顯示多個檔案的內容。
示例: more file1.txt file2.txt
輸出:
Contents of file1.txt --More--(file 1 of 2)
輸出結果顯示了 file1.txt
的內容,並指出這是兩個檔案中的第一個。您可以使用與檢視單個檔案相同的控制元件瀏覽檔案。
3. 在檔案內搜尋
語法: more [filename], then type /pattern to search.
說明:允許在檔案中搜尋特定規則。
示例: more myfile.txt, then type /line 3
輸出:
This is line 3 --More--(20%)
用 more
開啟 myfile.txt
後,鍵入 /line 3
搜尋文字 line 3
,並顯示相應的行,表明已顯示檔案的 20%。
4. 檢視帶行號的檔案
語法: more -n [filename]
說明:顯示帶有行號的檔案內容。
示例: more -n myfile.txt
輸出:
1 This is line 1 2 This is line 2 --More--(10%)
輸出結果顯示了 myfile.txt
的前幾行和行號,並指出已顯示檔案的 10%。
5. 以每屏特定行數檢視檔案
語法: more -num [filename]
說明:以每屏特定行數顯示檔案內容。
示例: more -5 myfile.txt
輸出:
This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 --More--(25%)
輸出結果顯示了 myfile.txt
的前五行,並表明已顯示檔案的 25%。
6. 管道輸出到 “more”
語法: [command] | more
說明:將另一條命令的輸出通過 more
命令列傳送,以便在一個螢幕上同時檢視。
示例: ls -l | more
輸出:
-rw-r--r-- 1 user user 1234 Jan 1 12:00 file1.txt -rw-r--r-- 1 user user 5678 Jan 1 12:01 file2.txt --More--
輸出結果顯示當前目錄下的檔案長列表,每次顯示一屏。 --More--
提示表示還有更多內容需要檢視。
7. 檢視檔案並在規則首次匹配時退出
語法: more +/pattern [filename]
說明:開啟檔案並直接跳轉到指定模式的首次出現處。
示例: more +/line3 myfile.txt
輸出:
This is line 3 This is line 4 --More--(20%)
輸出顯示的內容從 myfile.txt
中出現的 line3
開始,表明已顯示檔案的 20%。
更多 Linux 命令
下面羅列了最常見的一些 Linux 命令,您可以根據自己的需要查閱對應命令的詳細解析:
目錄操作 | rmdir · cd · pwd · exa · ls |
檔案操作 | cat · cp · dd · less · touch · ln · rename · more · head |
檔案系統操作 | chown · mkfs · locate |
網路 | ping · curl · wget · iptables · mtr |
搜尋和文字處理 | find · grep · sed · whatis · ripgrep · fd · tldr |
系統資訊和管理 | env · history · top · who · htop · glances · lsof |
使用者和會話管理 | screen · su · sudo · open |
此外,我們還整理 Linux 命令列大全,以幫助大家全面深入地學習 Linux。
評論留言