看檔案內容的指令琳瑯滿目,各有用途:
cat -n # 連行號輸出,類似 nl more test.txt # 一頁頁顯示 ls -al | more # 把 ls 輸出分頁顯示 less test.txt # 可 pageup/pagedown 翻看 less 內按 /word # 搜尋 word 字串 less 內按 :q # 退出 less head -n 20 test.txt # 顯示前 20 行 tail -n 20 test.txt # 顯示後 20 行 head -n 20 test.txt | tail -n 10 # 取第 11~20 行
其中 less 比 more 更有彈性,支援搜尋與雙向翻頁;head 搭配 tail 則能精準截取檔案中特定區段的行。