WebMasterCampus
WEB DEVELOPER Resources

Linux tail Command

Learn Linux tail Command with examples


Linux tail Command

In Linux we use “tail” command to output the end of a file.

The Linux tail command allows us to check if a file has new data attached.

web servers like Apache or nginx write status information into so-called log files.

tail Command Syntax

~$  tail [options] <files>

tail Command Example

~$  tail logfile

tail Command Display multiple files

~$  tail logfile1, logfile2

The Linux tail command can be controlled using parameters.

Option
(short-form/long-form)
Explanation
-n / --lines Limit output to the last n lines/limit output to the lines following from line n
-c / --bytes Limit output to the last n bytes/limit output to the bytes following from byte n
-q / --quiet --silent When using multiple files suppress the output of the file names
-v / --verbose Force output of file names when used with multiple files
--help View Help section for command
--version View version information of

Display the Number of Lines

tail ‘-n’ option displays the specified number of lines.

~$  tail -n <number> <file name>  

~$  tail -n 5 num.txt  

Display Specified Number of Bytes

tail ‘-c’ option displays the specified number of bytes from the last. To display the specified number of bytes, run the following command.

~$  tail -c <number> <file name>  

~$  tail -c 6 num.txt  

use the suffix with the number such as b, kb, k, MB, and more to specify the number of bytes.

tail Command Can be Used with Other Commands

tail Command can be piped with other commands like ls command. It will display the four files or folders modified the longest time ago.

~$  ls -t /bin | tail -n 4

ps Command to display the top running process pipe with tail

Use ps command to display the top running process pipe with tail command.

~$ ps aux | sort -nk +3 | tail -2
Created with love and passion.