Linux command: tail
Many programs keep a log file, a running record of events such as starts, warnings, and errors. When a problem just happened, the newest lines are often the first place to look. tail prints the end of a file or a stream, so it can show recent records without making you read the entire file. A stream is data arriving from another command or program. This makes tail useful both for checking a saved file and for watching new output.
With no option, tail outputs the last ten lines; -n 50 selects fifty lines, while -c 512 selects the last 512 bytes. A starting position can also be given with a plus sign: tail -n +2 file.txt prints from line two through the end. With no file, or with - as the filename, tail reads standard input and can finish a pipeline. For standard input from a pipe or FIFO, GNU tail ignores -f when no file operand is given or the operand is -; there is no path to reopen.
For example, tail -n 30 application.log gives a quick view of recent records without printing the entire file. When multiple files are supplied, tail usually prints a header before each file's output. That is useful for a person comparing logs, but scripts should account for headers. A text line is not necessarily a complete application event when records span multiple lines.
To watch new output from a running program, use -f:
tail -n 50 -f application.log
By default, GNU tail follows the opened file descriptor. If rotation renames that file and creates a new file at the same path, descriptor following can remain attached to the old file. GNU tail's -F follows the filename and retries when it is removed or temporarily unavailable. tail -F application.log is useful for a log that is renamed and recreated. -F is a GNU extension; check the local manual before using it in a portable script.
No new output does not prove that the application stopped. It may be writing to another path, buffering records, or keeping the old file open. Confirm the configured pathname, process, file timestamps, and rotation method. If the active output is a system journal rather than a normal file, use a log reader such as journalctl.
tail can filter a stream without creating an intermediate file. For instance, journalctl -u example.service | tail -n 40 displays the last forty lines of that command's output, though the first command may still produce a large stream. Stop a follow process when it is no longer needed, especially if many files or users are being monitored.










