1. 程式人生 > >[linux]Linux如何檢視檔案中的中間部分內容

[linux]Linux如何檢視檔案中的中間部分內容


最基本的是cat、more和less。 
1. 如果你只想看檔案的前5行,可以使用head命令,如: 
head -5 /etc/passwd 
2. 如果你想檢視檔案的後10行,可以使用tail命令,如: 
tail -10 /etc/passwd 或 tail -n 10 /etc/passwd 
tail -f /var/log/messages 
引數-f使tail不停地去讀最新的內容,這樣有實時監視的效果 用Ctrl+c來終止! 
3. 檢視檔案中間一段,你可以使用sed命令,如: 
sed -n '5,10p' /etc/passwd 
這樣你就可以只檢視檔案的第5行到第10行。