The tail
command in Linux is used to display the last part of a file or the last few lines of a file. It’s especially useful for monitoring log files in real-time, as it can continuously display new lines as they are added to the file. By default, tail
shows the last 10 lines of a file, but you can customize this behavior with various options.
Basic usage:
tail [options] [file...]
Common options:
- -n [number], –lines=[number] Display the last [number] lines of the file Example:
tail -n 20 file.txt
- -f, –follow Output appended data as the file grows Example:
tail -f log_file.txt
- -F Similar to -f, but will keep trying to open a file if it becomes inaccessible
- -c [number], –bytes=[number] Output the last [number] bytes of the file Example:
tail -c 100 file.txt
- –pid=[PID] With -f, terminate after process ID, PID dies
- -q, –quiet, –silent Never output headers giving file names
- -v, –verbose Always output headers giving file names
- –retry Keep trying to open a file even if it is inaccessible when tail starts
- -s [seconds], –sleep-interval=[seconds] With -f, sleep for approximately [seconds] seconds between iterations
- +[number] Start output from line [number] Example:
tail +10 file.txt
(starts output from the 10th line)
Examples:
- Display the last 10 lines of a file (default behavior):

2 .Display the last 50 lines of a file:

3. Follow the growth of a log file in real-time:
tail -f /var/log/syslog
The tail
command is particularly useful for monitoring log files, viewing the most recent entries in a file, or following file changes in real-time.