GO KALI FREE
File Management

tail Linux Command

Displays the last 10 lines of a file. Use -f to follow file changes in real time.

What does tail do?

Displays the last 10 lines of a file. Use -f to follow file changes in real time.

Syntax

tail [options] filename

Practical example

tail -f /var/log/apache2/access.log

Questions about tail

How do I follow a log file in real time?

Use `tail -f filename` to continuously watch a file as new lines are added. This is essential for monitoring log files. Press Ctrl+C to stop.

How do I show the last 20 lines of a file?

Use `tail -n 20 filename` or `tail -20 filename` to display the last 20 lines. The default is 10 lines if no number is specified.

How do I follow a file by descriptor?

Use `tail -f --pid=PID filename` to stop following when process PID ends, or `tail -F filename` to follow by name (useful when file is rotated).

How do I combine multiple log files with tail?

Use `tail -f file1.log file2.log` to follow multiple files simultaneously. New entries from both files will be displayed.

How do I tail the last 100 lines of a file?

Use `tail -n 100 filename` to show the last 100 lines. This is useful for quickly checking recent activity in large files.

How do I use tail with a pipe?

Use `command | tail -n 20` to get the last 20 lines of a command's output. This is useful for seeing the final results of a long process.

What is the difference between tail -f and tail -F?

`tail -f` follows a file descriptor, while `tail -F` follows the filename. Use `-F` when the file might be rotated (renamed and recreated).

Related File Management

head

Displays the first 10 lines of a file by default. Use -n to specify count.

nano

Opens a simple, beginner-friendly terminal text editor.

more

Views file contents one screen at a time (forward-only navigation).

vim

Opens the powerful Vim text editor for editing files.

less

Views file contents page by page with forward and backward navigation.

wc

Counts lines, words, and characters in a file.