{"id":1785,"date":"2021-01-29T11:55:00","date_gmt":"2021-01-29T11:55:00","guid":{"rendered":"http:\/\/linoxide.com\/how-tos\/linux-tail-command\/"},"modified":"2026-01-29T12:23:39","modified_gmt":"2026-01-29T12:23:39","slug":"linux-tail-command","status":"publish","type":"post","link":"https:\/\/linoxide.com\/linux-command\/linux-tail-command\/","title":{"rendered":"Tail Command in Linux \u2013 Options +Example"},"content":{"rendered":"\n<p>In a Linux system, log data are normally added to the end of the file. You may require to see the new additions to the log file. Linux tail command is commonly used in this scenario to view those data.<\/p>\n\n\n\n<p>In this tutorial, we learn about the Linux tail command and its useful options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is tail command&nbsp;<\/h2>\n\n\n\n<p>Linux tail command is a complementary part of head command. It prints the last \u2018N\u2019 number of lines from one or more files. By default, it prints the last 10 lines of a provided file.<\/p>\n\n\n\n<p>Usually, in the data files such as error logs, access logs the data is added to the end of the file. The tail command helps to read last lines and monitor file changes in real-time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to use tail command&nbsp;<\/h2>\n\n\n\n<p>The basic syntax of Linux tail command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail &#91;OPTION]... &#91;FILE]...<\/code><\/pre>\n\n\n\n<p>For example, we have created a text file named \u2018country.txt\u2019. In this file, we copied the names of different countries in the world. To view the file content we may use cat command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat country.txt<\/code><\/pre>\n\n\n\n<p>Display the same file data using the tail command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail country.txt<\/code><\/pre>\n\n\n\n<p>When we use the tail command without any option, it prints only the last 10 lines of a file.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tail Command Examples<\/h2>\n\n\n\n<p>Here we will check some of the commonly used tail commands with practical examples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Print the specified last lines<\/h3>\n\n\n\n<p>Using the tail command, we can print the specified last lines of a file. To print the last 4 number of lines from a specified text file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -n 4 country.txt<\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -4 country.txt<\/code><\/pre>\n\n\n\n<p>One practical example, to check the last 100 lines from&nbsp;<code>\/var\/log\/syslog<\/code>&nbsp;file, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -n 100 \/var\/log\/syslog<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Prints lines from start of a specific line<\/h3>\n\n\n\n<p>Using the \u2018+\u2019 option with a number, we can display the file content from the start of a specified line number till the end. For example to print all contents of the file named country.txt from line 1, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail +1 country.txt<\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -n +1 country.txt<\/code><\/pre>\n\n\n\n<p>The following command prints file contents from line 4:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail +4 country.txt<\/code><\/pre>\n\n\n\n<p>This comes helpful when you have a large file and want to print from a particular line number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Print last specified bytes<\/h3>\n\n\n\n<p>Tail command is useful to display the last specified number of characters or bytes from a file. For example, to print the last 6 characters or bytes from a file named&nbsp;<code>country.txt<\/code>, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -c -6 country.txt<\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -c 6 country.txt<\/code><\/pre>\n\n\n\n<p>With the positive number, it prints file content after skipping that much number of bytes from the start of the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -c +6 country.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">tail command and multiple files<\/h3>\n\n\n\n<p>You can use multiple files with tail command. By default, if you pass multiple files it prints the file names in between.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail food.txt country.txt<\/code><\/pre>\n\n\n\n<p>To ignore filenames, use&nbsp;<code>-q<\/code>&nbsp;option when using more than one file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -q food.txt country.txt<\/code><\/pre>\n\n\n\n<p>This prints the last 10 lines of both files without displaying the filenames.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Monitor files real-time<\/h3>\n\n\n\n<p>Monitoring the new text entries especially logs files is one of the best use of the tail command. Use the tail command followed by&nbsp;<code>f<\/code>&nbsp;option to track files. By default it tail -f command shows the last 10 lines and the console will show the new lines when the file gets updated.<\/p>\n\n\n\n<p>For example to track&nbsp;<code>\/var\/log\/syslog<\/code>&nbsp;file in real-time, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -f \/var\/log\/syslog<\/code><\/pre>\n\n\n\n<p>You need to press the interrupt key&nbsp;to return back to the command prompt.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Use tail command with other commands<\/h3>\n\n\n\n<p>We can also use the Linux tail command in conjunction with other Linux commands. For example, you can use the sort command piped with the tail command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail \u2013n 5 country.txt | sort<\/code><\/pre>\n\n\n\n<p>This prints the last 5 lines and sort them alphabetically.&nbsp;<\/p>\n\n\n\n<p>You may also use the tail command along with head command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail \u2013n +5 country.txt | head \u2013n 2<\/code><\/pre>\n\n\n\n<p>This is another useful example where we can combine tail command along with nl command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nl coountry.txt | tail -7<\/code><\/pre>\n\n\n\n<p>This prints the last specified number of lines with line numbers:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tail Commands Options<\/h2>\n\n\n\n<p>Some of the useful options of tail command are:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Options<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>-n<\/code>&nbsp;Num<\/td><td>Prints the last Num lines.<\/td><\/tr><tr><td><code>-c<\/code>&nbsp;Num<\/td><td>Print the last Num bytes<\/td><\/tr><tr><td><code>-q<\/code>&nbsp;<\/td><td>Hide the headers of a given file names<\/td><\/tr><tr><td><code>-f<\/code><\/td><td>Display appended data as the file grows<\/td><\/tr><tr><td><code>-v<\/code><\/td><td>Prints the specified file names at the beginning of the output<\/td><\/tr><tr><td><code>--version<\/code><\/td><td>Prints the installed version information<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion&nbsp;<\/h3>\n\n\n\n<p>In this tutorial, we learned the basic functionality of tail command and how it can be used to show the contents from the end of a file. Tail command has very few options which we have explained with examples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a Linux system, log data are normally added to the end of the file. You may require to see the new additions to the log file. Linux tail command is commonly used in this scenario to view those data. In this tutorial, we learn about the Linux tail command and its useful options. What is tail command&nbsp; Linux tail command is a complementary part of head command. It prints the last \u2018N\u2019 number of lines from one or more files. By default, it prints the last 10 lines of a provided file. Usually, in the data files such as<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[27],"tags":[],"class_list":["post-1785","post","type-post","status-publish","format-standard","hentry","category-linux-command"],"_links":{"self":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/1785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/comments?post=1785"}],"version-history":[{"count":1,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/1785\/revisions"}],"predecessor-version":[{"id":1825,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/1785\/revisions\/1825"}],"wp:attachment":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/media?parent=1785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/categories?post=1785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/tags?post=1785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}