tail command

LINUX-Frequently used commands

tail command Display the contents of a file only at the end.
Syntax
tail  [Option]  [file-name]
The tail command can be used to display the contents of a specified file, starting from the end and continuing for a specified number of lines.
If no number of lines is specified, 10 lines are displayed by default.
The tail command can also be used in conjunction with the pipe feature to display a specified number of leading lines.
Frequently used options
-n [Number of lines]      Display the contents of a file for a specified number of lines from the beginning.
Example: Display only the end of a file's content.
$  tail  /var/usr/temp.txt  ← Display the last 10 lines of the file /var/usr/temp.txt
Example: List files in order of time type, with the oldest 5 files displayed first.
$  ls -lrt  /var/usr/ | tail -n 5
-rw-rw-r-- 1koro koro 12345 Jan 27 02:48 temp1.txt
-rw-rw-r-- 1koro koro 3333 27 Feb 02:48 temp2.txt
-rw-rw-r-- 1koro koro 345 Mar 27 02:48 temp3.txt
-rw-rw-r-- 1koro koro 12 Apr 27 02:49 temp4.txt
-rw-rw-r-- 1koro koro 144 May 27 02:49 temp5.txt
Use "|" (pipe) between commands and "ls -lrt" to extract 5 results from the oldest date using "tail -n 5".
Copied title and URL