Refer to "Linux Shell Script Raiders 2nd Edition"
1,head
A) print the first 10 lines:
[Email protected]:~$ head file
b) Print the first 5 lines:
[email protected]:~$ head-N 5 file or [email protected]:~$ head-5 file
c) Print all lines except for the last M line:
[email protected]:~$ head-n-m file
2,tail
A) print the last 10 lines of the file:
[email protected]:~$Tail file
b) Print the last 5 lines:
[email protected]:~$tail-N 5 file or [email protected]:~$Tail -5 file
c) Print all rows except for the first m line:
[email protected]:~$tail -n + (m+1) file
d) Tail-f can keep a close eye on the new additions in the file and continue to update as the data increases, which can be added with a sleep interval-s so that we can set the time interval for the watch file (if the fun keeps appending data to the monitored file, tail-f Will always be executed know the process fun end ):
Pgrep Fun | Xargs tail-f file-s--pid
Pidof Fun | Xargs tail-f file-s--pid
Head&&tail