{"id":15770,"date":"2019-03-04T09:49:07","date_gmt":"2019-03-04T09:49:07","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15770"},"modified":"2026-03-10T10:25:05","modified_gmt":"2026-03-10T10:25:05","slug":"how-to-use-tail-command","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-use-tail-command","title":{"rendered":"What Is Linux tail Command and How to Use It With head Command"},"content":{"rendered":"<p>The Linux <strong>tail <\/strong>command displays the latest content from the end of a chosen file or files directly to the screen. This function is useful for instantly viewing recent additions to files, as new information is often appended at the end.<\/p><p>System administrators commonly combine it with other Linux commands like <strong>sort<\/strong> or <strong>rm<\/strong> to manipulate the output. Moreover, they can add various options to modify the utility&rsquo;s behavior based on the tasks.<\/p><p>To help improve your virtual private server (VPS) management efficiency, this article will explain Linux <strong>tail<\/strong> command basics. We will provide its syntax, share practical examples, and demonstrate how to combine it with the <strong>head <\/strong>utility.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet-1024x283.png\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-768x212.png 768w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>\n\n\n<div class=\"protip\">\n                    <h2 class=\"featured-snippet title\">What Is Tail Command?<\/h2>\n                    <p>The <strong>tail<\/strong> ommand outputs the last few lines of specified files, defaulting to ten lines unless adjusted by the user. It&rsquo;s frequently used for tracking log files and monitoring real-time updates. System administrators often combine it with other commands via pipes to customize the output. When no file is specified, it reads from standard input, and users can define the number of lines or bytes to display.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\">tail Command Syntax<\/h3><p>By default, <strong>tail<\/strong> displays the 10 last lines of a file. Here&rsquo;s the basic syntax:<\/p><pre class=\"wp-block-preformatted\">tail [file_name]<\/pre><p>You can use several options for customizing <strong>tail<\/strong> output. Here are some of the most popular ones with their long form and functions:<\/p><ul class=\"wp-block-list\">\n<li><strong>-c num <\/strong>or <strong>&ndash;bytes<\/strong> &#8210; outputs the last <strong>num<\/strong> bytes of data.<\/li>\n\n\n\n<li><strong>-n num<\/strong> or<strong> &ndash;lines <\/strong>&#8210; specifies the last <strong>num<\/strong> lines to show.<\/li>\n\n\n\n<li><strong>-f <\/strong>or<strong> &ndash;follow=name<\/strong> &#8210; monitors new entries as the file grows.<\/li>\n\n\n\n<li><strong>-v <\/strong>or <strong>&ndash;verbose<\/strong> &#8210; prints the file name before the data.<\/li>\n\n\n\n<li><strong>-q <\/strong>or<strong> &ndash;quiet, &ndash;silent<\/strong> &#8210; omits the file name before printing the data.<\/li>\n\n\n\n<li><strong>-version<\/strong> &#8210; displays the<strong> tail <\/strong>version information.<\/li>\n<\/ul><p><div><p class=\"important\"><strong>Important!<\/strong> Note that this Linux command syntax is case-sensitive.<\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-tail-command-examples\">tail Command Examples<\/h2><p>In this section, we will explore the common uses and practical examples of the Linux<strong> tail <\/strong>command. To run this command on a VPS, connect using an <a href=\"\/in\/tutorials\/how-to-use-putty-ssh\">SSH client like PuTTY<\/a> or Terminal. Alternatively, Hostinger users can use our <a href=\"https:\/\/support.hostinger.com\/en\/articles\/7978544-how-to-use-the-browser-terminal\" target=\"_blank\" rel=\"noopener\">Browser terminal<\/a><strong> <\/strong>feature.<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Suggested Reading<\/h4>\n                    <p>Haven&rsquo;t bought a VPS hosting plan? Check out our article on the <a href=\"\/in\/tutorials\/best-vps-hosting\">top VPS hosting providers<\/a> to learn about the best options for your needs.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\">Using tail to Print the Last 10 Lines<\/h3><p>The <strong>tail<\/strong> command&rsquo;s basic functionality is outputting the last 10 entries from a single file. To do so, run it without any option or flag like the following example:<\/p><pre class=\"wp-block-preformatted\">tail error.log<\/pre><p>If the log file adds a new entry at the bottom, the <strong>tail <\/strong>command will output it as the last line. By default, it presents the data in descending order, starting from the newest addition.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file.png\"><img decoding=\"async\" width=\"994\" height=\"300\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file.png\" alt=\"The tail command prints the last 10 lines of a log file\" class=\"wp-image-99349\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file.png 994w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file-300x91.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file-150x45.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file-768x232.png 768w\" sizes=\"(max-width: 994px) 100vw, 994px\" \/><\/a><\/figure><\/div><p>You can also specify the directory path. Here are example commands for tracking the 10 latest entries of different web servers&rsquo; log files:<\/p><pre class=\"wp-block-preformatted\">sudo tail -f \/var\/log\/apache2\/access.log<\/pre><pre class=\"wp-block-preformatted\">sudo tail -f \/var\/log\/nginx\/access.log<\/pre><h3 class=\"wp-block-heading\">Using tail to Print a Specific Number of Lines<\/h3><p>To display specific lines with <strong>tail<\/strong>, add the <strong>-n<\/strong> option to your command. Here&rsquo;s the syntax:<\/p><pre class=\"wp-block-preformatted\">tail -n [num] [file_name]<\/pre><p>See the following example command for printing the last two lines of the <strong>mynote.txt<\/strong> file:<\/p><pre class=\"wp-block-preformatted\">tail -n 2 mynote.txt<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file.png\"><img decoding=\"async\" width=\"872\" height=\"85\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file.png\" alt=\"The tail command prints the last two lines of a file\" class=\"wp-image-99351\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file.png 872w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file-300x29.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file-150x15.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file-768x75.png 768w\" sizes=\"(max-width: 872px) 100vw, 872px\" \/><\/a><\/figure><\/div><p>You can also omit the <strong>-n<\/strong> option and directly specify the number of lines to print as the flag, like this example:<\/p><pre class=\"wp-block-preformatted\">tail -2 mynote.txt<\/pre><h3 class=\"wp-block-heading\">Using tail to Specify the Number of Bytes<\/h3><p>The <strong>-c<\/strong> option displays the last number of bytes of the specified file. Administrators commonly use it for regular-sized files containing the <a href=\"https:\/\/www.asciitable.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">ASCII character set<\/a>, where one character corresponds to one byte.<\/p><p>Here is the syntax:<\/p><pre class=\"wp-block-preformatted\">tail -c [num] [file_name]<\/pre><p>The following example outputs the last 50 bytes or characters of the <strong>mynote.txt<\/strong> file:<\/p><pre class=\"wp-block-preformatted\">tail -c 50 mynote.txt<\/pre><p><div><p class=\"important\">The <strong>-c<\/strong> option in the <strong>tail<\/strong> command counts bytes rather than characters. Therefore, when working with files using the <a href=\"https:\/\/www.ibm.com\/docs\/en\/db2\/11.5?topic=support-unicode-character-encoding\" target=\"_blank\" rel=\"noopener\">Unicode character set<\/a>, especially those with multi-byte characters, specifying the last <strong>num<\/strong> bytes may not align with character boundaries, leading to potentially confusing output.<\/p><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\">Using tail to Sort Data<\/h3><p>Combine other utilities and options with <strong>tail<\/strong> to query data in a specific order. The command differs depending on how you want to display the information.<\/p><p>For instance, pipe the <strong>ls<\/strong> command with <strong>-t<\/strong> and<strong> -l<\/strong> options to list 10 items within the current directory with the oldest modification timestamps. Here&rsquo;s the syntax:<\/p><pre class=\"wp-block-preformatted\">ls -tl | tail -n [number_of_lines]<\/pre><p>You can also add the <strong>sort<\/strong> command with the<strong> -M<\/strong> option to reorder the output in ascending order based on the month of creation.<\/p><pre class=\"wp-block-preformatted\">ls -tl | sort -M | tail -n [number_of_lines]<\/pre><p>To reverse the output order, add the <strong>-r <\/strong>option to the <strong>tail <\/strong>command:<\/p><pre class=\"wp-block-preformatted\">tail -n [number_of_lines] [file_name] | sort -r<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order.png\"><img decoding=\"async\" width=\"859\" height=\"162\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order.png\" alt=\"The piped sort command reverses the tail output order\" class=\"wp-image-99352\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order.png 859w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order-300x57.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order-150x28.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order-768x145.png 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\">Using tail to Monitor a File for Changes<\/h3><p>The <strong>&ndash;follow<\/strong> or<strong> -f <\/strong>option lets you run the <strong>tail<\/strong> command continuously, updating the output in real time whenever the specified file receives new data. Here&rsquo;s the syntax:<\/p><pre class=\"wp-block-preformatted\">tail -f [file_name]<\/pre><p>The header line will highlight the changes in the original file. You can also specify the name as the option&rsquo;s value like the following:<\/p><pre class=\"wp-block-preformatted\">tail --follow=name [file_name]<\/pre><p>If you don&rsquo;t specify the name, the option will use the &ldquo;<strong>descriptor<\/strong>&rdquo; default value. It means the command will continue to print new lines from the same file during log rotation.<\/p><p>Even if you rename it or create a new file with the same name, the command will keep monitoring the same one. Using the uppercase<strong> -F <\/strong>option yields the same behavior.<\/p><p>Optionally, add the <strong>&ndash;max-unchanged-stats<\/strong> option to hide identical lines after a specific number of occurrences, simplifying Linux log monitoring. Here&rsquo;s the command:<\/p><pre class=\"wp-block-preformatted\">tail -f --max-unchanged-stats=5 error.log<\/pre><p>To stop printing the new data, quit the update mode by pressing the <strong>Ctrl+C <\/strong>shortcut. A common <strong>tail -f <\/strong>usage includes real-time log viewing since new status information typically shows at the bottom of a file.<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Pro Tip<\/h4>\n                    <p>For continuous log file analysis, run the <strong>tail -f<\/strong> command in another terminal instance using a multiplexer like <a href=\"\/in\/tutorials\/how-to-install-and-use-linux-screen\/\">Linux Screen<\/a> to keep the process running in the background.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\">Using tail Command for Multiple Files<\/h3><p>Processing multiple files simultaneously using the <strong>tail <\/strong>command requires you to list their names like the following:<\/p><pre class=\"wp-block-preformatted\">tail [option] [file_name_1] [file_name_2] [file_name_3]<\/pre><p>For instance, we will print five lines from multiple text files:<\/p><pre class=\"wp-block-preformatted\">tail -n 5 file1.txt file2.txt file3.txt<\/pre><p>If you run the <strong>tail <\/strong>command with multiple file names, Terminal will display headers specifying them.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files.png\"><img decoding=\"async\" width=\"1024\" height=\"491\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files-1024x491.png\" alt=\"The tail command prints the last five lines of multiple files\" class=\"wp-image-99353\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files-300x144.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files-150x72.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files-768x368.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>Hide the file header by adding the <strong>-q <\/strong>option to enable quiet mode, omitting the information:<\/p><pre class=\"wp-block-preformatted\">tail -q [file_name]<\/pre><h3 class=\"wp-block-heading\">Using tail to Track System Resource Usage<\/h3><p>Combine the <strong>tail <\/strong>command with resource tracking utilities to monitor your system hardware usage. Here&rsquo;s an example syntax:<\/p><pre class=\"wp-block-preformatted\">command [interval] | tail -n [number_of_lines]<\/pre><p>The resource tracking utility logs hardware usage at specified intervals. The <strong>tail<\/strong> command retrieves the data and outputs the last few lines.<\/p><p>For example, enter the following command to track the last five virtual memory usage logs, refreshing every second:<\/p><pre class=\"wp-block-preformatted\">vmstat 1 | tail -n 5<\/pre><p>To track your VPS I\/O statistics, pipe the <strong>iostat <\/strong>command like the following:<\/p><pre class=\"wp-block-preformatted\">iostat 1 | tail -n 5<\/pre><p>Meanwhile, combine <strong>tail <\/strong>with the <a href=\"\/in\/tutorials\/netstat-command\"><strong>netstat <\/strong>command<\/a> to monitor network-related resource usage:<\/p><pre class=\"wp-block-preformatted\">netstat 1 | tail -n 5<\/pre><p>If Terminal shows the &ldquo;<strong>Command not found<\/strong>&rdquo; error, install the resource tracking utilities using the following:<\/p><pre class=\"wp-block-preformatted\">sudo apt install net-tools procps sysstat<\/pre><p>Instead of commands, <a href=\"\/in\/vps-hosting\">Hostinger VPS service<\/a> users can check their server resource usage with our monitoring feature that offers a graphical user interface. To access it, go to <a href=\"\/support\/1583483-comprehensive-guide-to-hpanel-at-hostinger\/\">hPanel<\/a> &rarr; <strong>Backup &amp; Monitoring<\/strong> &rarr; <strong>Server Usage<\/strong>.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel.png\"><img decoding=\"async\" width=\"1024\" height=\"291\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel-1024x291.png\" alt=\"Hostinger VPS resource monitoring dashboard in hPanel\" class=\"wp-image-99354\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel-1024x291.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel-300x85.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel-150x43.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel-768x218.png 768w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel.png 1447w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/in\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\">Using tail Command With Pipes<\/h3><p>In Linux operating systems, a pipe (<strong>|<\/strong>) is a standard output redirection. It lets a command pass its retrieved information to another utility as input.<\/p><p>In addition to file content, use a pipe to pass another utility&rsquo;s output to the <strong>tail <\/strong>command. Here&rsquo;s the syntax:<\/p><pre class=\"wp-block-preformatted\">command | tail -n [number of lines]<\/pre><p>For example, the <strong>netstat <\/strong>command prints many lines by default. However, piping its output to the <strong>tail <\/strong>utility lets you retrieve only the newest data for simpler analysis.<\/p><h2 class=\"wp-block-heading\" id=\"h-using-the-head-command-with-tail\">Using the head Command With Tail<\/h2><p>The Linux <strong>head<\/strong> command prints the first few lines of one or multiple files as a standard output. Like the <strong>tail <\/strong>utility, it is a part of the <strong>GNU Coreutils<\/strong>. Here&rsquo;s its basic syntax:<\/p><pre class=\"wp-block-preformatted\">head -[option] [file_name]<\/pre><p>You can use some of the<strong> tail <\/strong>command options with <strong>head<\/strong>. For example, add<strong> -n<\/strong> to print the first <strong>num <\/strong>lines from a file.<\/p><p>Combining <strong>head<\/strong> and <strong>tail<\/strong> commands allows you to output a specific section from a file.<\/p><p>For example, use the <strong>head<\/strong> command to extract the first lines from a file. Pipe the data as a standard input to <strong>tail<\/strong> to display the last few entries from that particular section. Consider these commands:<\/p><pre class=\"wp-block-preformatted\">head -n 20 access.log | tail -10<\/pre><pre class=\"wp-block-preformatted\">head -n 20 error.log | tail -10<\/pre><p>In the above examples, the <strong>head<\/strong> command retrieves the first 20 lines from the two log files and passes them through the pipe as input. Then,<strong> tail<\/strong> prints the last 10 lines.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-and-head-command-output-the-last-few-lines-of-a-file-starting-from-the-fifth.png\"><img decoding=\"async\" width=\"832\" height=\"158\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-and-head-command-output-the-last-few-lines-of-a-file-starting-from-the-fifth.png\" alt=\"The tail and head command output the last few lines of a file starting from the fifth\" class=\"wp-image-99355\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-and-head-command-output-the-last-few-lines-of-a-file-starting-from-the-fifth.png 832w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-and-head-command-output-the-last-few-lines-of-a-file-starting-from-the-fifth-300x57.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-and-head-command-output-the-last-few-lines-of-a-file-starting-from-the-fifth-150x28.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/the-tail-and-head-command-output-the-last-few-lines-of-a-file-starting-from-the-fifth-768x146.png 768w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/a><\/figure><\/div><p>To extract the first <strong>num<\/strong> lines starting from a particular entry, specify the number to the <strong>tail<\/strong> command&rsquo;s <strong>-n<\/strong> value. For example, here&rsquo;s how to output entries starting from line number <strong>five<\/strong>:<\/p><pre class=\"wp-block-preformatted\">head -n 10 mynote.txt | tail -5<\/pre><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>The Linux <strong>tail <\/strong>command prints the last few lines of a file as a standard output. It helps simplify tasks like monitoring log files since system administrators don&rsquo;t need to manually reopen them to check for new data.<\/p><p>This command-line utility retrieves the last 10 lines by default, but you can display a specified number of entries using the<strong> -n <\/strong>option. You can also specify multiple file names and print data based on their byte value.<\/p><p>Moreover, users can combine <strong>tail <\/strong>with<strong> <\/strong>other Linux command-line tools using a pipe (<strong>|<\/strong>) to modify the output for specific tasks. For example, add <strong>netstat<\/strong>, <strong>iostat<\/strong>, and <strong>vmstat<\/strong> to check the latest system resource usage log. <\/p><p>It&rsquo;s also possible to combine it with the <strong>head <\/strong>utility to retrieve a particular section of a file. In addition, pipe the <strong>sort <\/strong>command to reorder the <strong>tail<\/strong> output based on your needs for simpler analysis.<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Learn More Linux Commands for Reading Files<\/h4>\n                    <p><a href=\"\/in\/tutorials\/linux-cat-command-tutorial-and-examples\/\">How to Read the Content of a File<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-use-linux-sed-command-examples\/\">How to Read a File With Sed Command<\/a><br>\n<a href=\"\/in\/tutorials\/linux-tee-command-with-examples\/\">How to Write and Display to File With Tee Command<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-kill-a-process-in-linux\">How to Kill a Process in Linux<\/a><br>\n<a href=\"\/in\/tutorials\/linux-shutdown-command\/\"> How to Use the Linux Shutdown Command<\/a><br>\n<a href=\"\/in\/tutorials\/using-scp-command-to-transfer-files\/\">How to Use SCP Command to Copy and Transfer Files in Linux<\/a><\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-tail-command-faq\">Tail Command FAQ<\/h2><p>In this section, we will answer several common questions about the Linux <strong>tail<\/strong> command to help expand your understanding of it.<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1642743487629\"><h3 class=\"schema-faq-question\"><strong>How Do You Grep Tail Command?<\/strong><\/h3> <p class=\"schema-faq-answer\">Using the <strong>tail<\/strong> and <strong>grep<\/strong> combo requires turning on the line buffering mode. It allows the process to resume the search while reducing delay.<br><br>To do so, write <strong>tail<\/strong> with the<strong> -f <\/strong>option and the file name. Then, pipe the <a href=\"\/in\/tutorials\/grep-command-in-linux-useful-examples\/\">grep command<\/a> with the <strong>&ndash;line-buffered<\/strong> option and the pattern to search.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1642743513572\"><h3 class=\"schema-faq-question\"><strong>How Do I Get Out of Tail Command in Linux?<\/strong><\/h3> <p class=\"schema-faq-answer\">To stop the <strong>tail<\/strong> command process and restore the terminal window, press <strong>Ctrl+C<\/strong>. This shortcut sends the <strong>SIGINT<\/strong> signal, telling the command-line interface to finish the process properly.<br><br>We don&rsquo;t recommend using the <strong>SIGKILL<\/strong> signal since it forcefully terminates the process, potentially causing issues.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1701658057217\"><h3 class=\"schema-faq-question\">How Do I Redirect the Output of tail to a File?<\/h3> <p class=\"schema-faq-answer\">To redirect the <strong>tail<\/strong> command output to a file, use the greater than symbol (<strong>&gt;<\/strong>) and specify where you want to store the data. For example, running <strong>tail data.txt &gt; log_file.txt <\/strong>will save <strong>data.txt<\/strong>&rsquo;s last 10 entries into the <strong>log_file.txt<\/strong> file.<br><br>When redirecting output, ensure your current user has the <strong>write<\/strong> permission over the target file.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Linux tail command displays the latest content from the end of a chosen file or files directly to the screen. This function is useful for instantly viewing recent additions to files, as new information is often appended at the end. System administrators commonly combine it with other Linux commands like sort or rm to [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-use-tail-command\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":115,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22644,22640],"tags":[],"class_list":["post-15770","post","type-post","status-publish","format-standard","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-use-tail-command","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/commande-tail-de-linux","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/comando-tail-linux","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-use-tail-command","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-use-tail-command\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-use-tail-command\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/comando-tail-linux\/","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/comando-tail-linux\/","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/comando-tail-linux","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-use-tail-command","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-use-tail-command","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-use-tail-command","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-use-tail-command","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/15770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/115"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=15770"}],"version-history":[{"count":34,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/15770\/revisions"}],"predecessor-version":[{"id":129919,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/15770\/revisions\/129919"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=15770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=15770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=15770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}