{"id":11380,"date":"2021-10-29T10:28:40","date_gmt":"2021-10-29T10:28:40","guid":{"rendered":"https:\/\/linuxways.net\/?p=11380"},"modified":"2021-10-29T10:28:40","modified_gmt":"2021-10-29T10:28:40","slug":"tail-command-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/tail-command-in-linux\/","title":{"rendered":"tail Command in Linux"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>tail command is the supplement of the head command. This command tells you the last data of the file input. Normally by default, the tail command prints out the last 10 lines of the file.<\/p>\n<p>tail command is the best and useful way to see the most recently added data. It can also monitor a file and show each new data added to that file as they happen.<\/p>\n<p>Below is the section that guides you on how to use the tail command in Linux as you go through below.<\/p>\n<h2>The syntax of tail command<\/h2>\n<pre>$ tail [option]... [file]...<\/pre>\n<p>Here I have a file named animal.txt. Let&#8217;s see what&#8217;s inside:<\/p>\n<pre>$ cat animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"291\" class=\"wp-image-11381\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-443.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-443.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-443-300x84.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-443-1024x286.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-443-768x214.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<h2>Options<\/h2>\n<p><strong>1.<\/strong> Without any option it will print out the last 10 lines<\/p>\n<pre>$ tail animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"251\" class=\"wp-image-11382\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-444.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-444.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-444-300x72.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-444-1024x247.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-444-768x185.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p><strong>2. -n num<\/strong>: Specifies the number of last lines to be printed<\/p>\n<p>For example, I will print out the last 3 lines:<\/p>\n<pre>$ tail -n 3 animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"105\" class=\"wp-image-11383\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-445.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-445.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-445-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-445-1024x103.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-445-768x77.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p>Another way:<\/p>\n<pre>$ tail -3 animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1043\" height=\"106\" class=\"wp-image-11384\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-446.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-446.png 1043w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-446-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-446-1024x104.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-446-768x78.png 768w\" sizes=\"auto, (max-width: 1043px) 100vw, 1043px\" \/><\/p>\n<p>With + option, it will print out from the specified line to the last line<\/p>\n<p>For example, I will print out from the 4th line to the last line:<\/p>\n<pre>$ tail +4 animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1041\" height=\"232\" class=\"wp-image-11385\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-447.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-447.png 1041w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-447-300x67.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-447-1024x228.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-447-768x171.png 768w\" sizes=\"auto, (max-width: 1041px) 100vw, 1041px\" \/><\/p>\n<p><strong>3. -c num<\/strong>: Prints out the last characters of the specified file. Each character is treated as 1 byte. With -num, it will print out the last <strong>num<\/strong> characters of the file. With +num, it will skip the first <strong>num<\/strong> characters and start printing out from the <strong>num<\/strong> character.<\/p>\n<p>For example, I will print out the last 3 characters:<\/p>\n<pre>$ tail -c -4 animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"73\" class=\"wp-image-11386\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-448.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-448.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-448-300x21.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-448-1024x72.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-448-768x54.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p>For example, I want to print out from the 4th byte:<\/p>\n<pre>$ tail -c +4 animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"286\" class=\"wp-image-11387\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-449.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-449.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-449-300x82.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-449-1024x281.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-449-768x211.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p><strong>4. -q<\/strong>: To execute multiple files at once<\/p>\n<p>I will use the tail command with 2 files animal.txt and vege.txt:<\/p>\n<pre>$ tail animal.txt vege.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1041\" height=\"505\" class=\"wp-image-11388\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-450.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-450.png 1041w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-450-300x146.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-450-1024x497.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-450-768x373.png 768w\" sizes=\"auto, (max-width: 1041px) 100vw, 1041px\" \/><\/p>\n<p><strong>5. -v<\/strong>: Filenames always show the beginning<\/p>\n<pre>$ tail -v animal.txt<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"267\" class=\"wp-image-11389\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-451.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-451.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-451-300x77.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-451-1024x262.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-451-768x197.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p><strong>6. &#8211;version<\/strong>: Check your version<\/p>\n<pre>$ tail --version<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1041\" height=\"213\" class=\"wp-image-11390\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-452.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-452.png 1041w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-452-300x61.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-452-1024x210.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-452-768x157.png 768w\" sizes=\"auto, (max-width: 1041px) 100vw, 1041px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>We just showed you how to use the tail command in Linux.<\/p>\n<p>Thanks for reading!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction tail command is the supplement of the head command. This command tells you the last data of the file input. Normally by default, the tail command prints&hellip;<\/p>","protected":false},"author":1,"featured_media":11690,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[35,647],"class_list":["post-11380","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-linux","tag-tail-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=11380"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11380\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/11690"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=11380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=11380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=11380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}