{"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-10T09:30:47","modified_gmt":"2026-03-10T09:30:47","slug":"how-to-use-tail-command","status":"publish","type":"post","link":"\/ca\/tutorials\/how-to-use-tail-command\/","title":{"rendered":"What is the Linux tail command? how to use it with the head command?"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>The <strong>tail<\/strong> command in Linux prints the last N lines of a given file. By default, it shows the last 10 lines. When used with multiple files, tail displays each file&rsquo;s output preceded by its file name.<\/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 loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\"  sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/div><p>\n\n\n<div class=\"protip\"><div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                   What is the tail command?\n                <\/p>\n            <\/div>\n            <p class=\"protip__content\">The <strong>tail<\/strong> command 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><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-syntax-of-the-tail-command\">Syntax of the tail command<\/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 class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> Note that this Linux command syntax is case-sensitive.\n            <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-example-of-the-tail-command\">Example of the tail command<\/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=\"\/ca\/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            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Suggested Reading                <\/p>\n            <\/div>\n            <p class=\"protip__content\">Haven&rsquo;t bought a VPS hosting plan? Check out our article on the <a href=\"\/ca\/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\n<\/p><h3 class=\"wp-block-heading\" id=\"h-using-tail-to-print-the-last-10-lines\">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=\"\/ca\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file.png\"><img loading=\"lazy\" decoding=\"async\" width=\"994\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-10-lines-of-a-file.png\/public\" alt=\"The tail command prints the last 10 lines of a log file\" class=\"wp-image-99349\"  sizes=\"auto, (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\" id=\"h-using-tail-to-print-a-specific-number-of-lines\">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=\"\/ca\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file.png\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"85\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-two-lines-of-a-file.png\/public\" alt=\"The tail command prints the last two lines of a file\" class=\"wp-image-99351\"  sizes=\"auto, (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\" id=\"h-using-tail-to-specify-the-number-of-bytes\">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 class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                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.\n            <\/p><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-using-tail-to-sort-data\">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=\"\/ca\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order.png\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"162\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/the-piped-sort-command-reverse-the-tail-output-order.png\/public\" alt=\"The piped sort command reverses the tail output order\" class=\"wp-image-99352\"  sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-using-tail-to-monitor-a-file-for-changes\">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            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Pro Tip                <\/p>\n            <\/div>\n            <p class=\"protip__content\">For continuous log file analysis, run the <strong>tail -f<\/strong> command in another terminal instance using a multiplexer like <a href=\"\/ca\/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\n<\/p><h3 class=\"wp-block-heading\" id=\"h-using-the-tail-command-for-multiple-files\">Using the 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=\"\/ca\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"491\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/the-tail-command-prints-the-last-five-lines-of-multiple-files.png\/w=1024,h=1024,fit=scale-down\" alt=\"The tail command prints the last five lines of multiple files\" class=\"wp-image-99353\"  sizes=\"auto, (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\" id=\"h-using-tail-to-track-system-resource-usage\">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=\"\/ca\/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=\"\/ca\/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=\"\/ca\/tutorials\/hpanel-tutorial\/\">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=\"\/ca\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1447\" height=\"411\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/hostinger-vps-resource-monitoring-dashboard-in-hpanel.png\/w=1024,h=1024,fit=scale-down\" alt=\"Hostinger VPS resource monitoring dashboard in hPanel\" class=\"wp-image-99354\"  sizes=\"auto, (max-width: 1447px) 100vw, 1447px\" \/><\/a><\/figure><\/div><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ca\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\" id=\"h-using-the-tail-command-with-pipes\">Using the 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=\"\/ca\/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 loading=\"lazy\" decoding=\"async\" width=\"832\" height=\"158\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/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\/public\" alt=\"The tail and head command output the last few lines of a file starting from the fifth\" class=\"wp-image-99355\"  sizes=\"auto, (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            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Learn More Linux Commands for Reading Files                <\/p>\n            <\/div>\n            <p class=\"protip__content\"><a href=\"\/ca\/tutorials\/linux-cat-command-tutorial-and-examples\/\">How to Read the Content of a File<\/a><br>\n<a href=\"\/ca\/tutorials\/how-to-use-linux-sed-command-examples\/\">How to Read a File With Sed Command<\/a><br>\n<a href=\"\/ca\/tutorials\/linux-tee-command-with-examples\/\">How to Write and Display to File With Tee Command<\/a><br>\n<a href=\"\/ca\/tutorials\/how-to-kill-a-process-in-linux\/\">How to Kill a Process in Linux<\/a><br>\n<a href=\"\/ca\/tutorials\/linux-shutdown-command\/\"> How to Use the Linux Shutdown Command<\/a><br>\n<a href=\"\/ca\/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\n<\/p><h2 class=\"wp-block-heading\" id=\"h-linux-tail-command-faq\">Linux 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 the 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=\"\/ca\/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 the 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 tail command in Linux prints the last N lines of a given file. By default, it shows the last 10 lines. When used with multiple files, tail displays each file&rsquo;s output preceded by its file name. System administrators commonly combine it with other Linux commands like sort or rm to manipulate the output. Moreover, [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ca\/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":"Linux tail Command Examples for %currentyear%","rank_math_description":"The tail command in Linux prints the last 10 lines of a file. Learn more useful examples of how to use this command in this article.","rank_math_focus_keyword":"tail command","footnotes":""},"categories":[22703,22699],"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-GB","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\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/15770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/users\/115"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/comments?post=15770"}],"version-history":[{"count":39,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/15770\/revisions"}],"predecessor-version":[{"id":139853,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/15770\/revisions\/139853"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media?parent=15770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/categories?post=15770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/tags?post=15770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}