Linux tail Command
The tail command is used to view the contents of a file. A commonly used parameter is -f
, which is often used to read log files that are being updated.
tail -f filename
will display the last part of the content in the filename file on the screen and continuously refresh, allowing you to see the latest file content as soon as filename is updated.
Command Format:
tail [parameter] [file]
Parameters:
-f Loop and read
-q Do not show processing information
-v Show detailed processing information
-c<number> Display the specified number of bytes
-n<lines> Display the last n lines of the file
--pid=PID Used with -f, it ends after the process ID, PID, dies
-q, --quiet, --silent Never output headers giving file names
-s, --sleep-interval=S Used with -f, it sleeps for S seconds between iterations
Examples
To display the last 10 lines of the notes.log file, enter the following command:
tail notes.log # Default displays the last 10 lines
To track the growth of a file named notes.log, enter the following command:
tail -f notes.log
This command displays the last 10 lines of the notes.log file. As lines are added to the notes.log file, the tail command continues to display them. The display continues until you press (Ctrl-C) to stop it.
To display the contents of the notes.log file from line 20 to the end:
tail -n +20 notes.log
To display the last 10 characters of the notes.log file:
tail -c 10 notes.log