{"id":15411,"date":"2022-02-21T07:48:40","date_gmt":"2022-02-21T07:48:40","guid":{"rendered":"https:\/\/linuxways.net\/?p=15411"},"modified":"2022-02-21T07:48:40","modified_gmt":"2022-02-21T07:48:40","slug":"how-to-view-data-with-the-tail-command-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-view-data-with-the-tail-command-in-linux\/","title":{"rendered":"How to View Data with the Tail Command in Linux"},"content":{"rendered":"<p>There are many ways to display data from files and one of them is by using the &#8220;tail command&#8221;. This article is all about seeing data with the tail command in different ways on Ubuntu 20.04. The tail command, which is pre-installed in all Linux distributions, prints the last number (N) of data from the provided input. The last ten lines of a file can be displayed by the tail command by default. This command is very useful if we want to see just the last part of a bigger file. It will save screen space and also your time. It can keep a record of real-time file modifications.<\/p>\n<p>This article will be very helpful for Linux users, especially newcomers, as they will learn different ways to display data from files using tail commands.<\/p>\n<h2><strong>How to view Data using Tail command<\/strong><\/h2>\n<p>There are various ways to display data using the tail command as mentioned below; you can use any of the methods according to your requirements.<\/p>\n<ul>\n<li>How to view Data from Single File Using Tail command<\/li>\n<li>How to view Data from Multiple File Using Tail command<\/li>\n<li>How to view Data from File Using Tail command with Different Options<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<p>The general syntax for the tail command is mentioned below:<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail [options] filename<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<h2><strong>How to view Data from Single File Using Tail command<\/strong><\/h2>\n<p>With the help of the tail command, you can view the last part of the file, below mentioned command will display the last 10 lines of the &#8220;linux.txt&#8221; file.<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail linux1.txt<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1344\" height=\"469\" class=\"wp-image-15412\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-555.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-555.png 1344w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-555-300x105.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-555-1024x357.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-555-768x268.png 768w\" sizes=\"auto, (max-width: 1344px) 100vw, 1344px\" \/><\/p>\n<h2><strong>How to view Data from Multiple File Using Tail command<\/strong><\/h2>\n<p>With the help of the tail command you can view the last part of more than one file, below mentioned command will display the last 10 lines of \u201clinux1.txt\u201d and \u201clinux2.txt\u201d files simultaneously.<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail linux1.txt linux2.txt<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1288\" height=\"180\" class=\"wp-image-15413\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-556.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-556.png 1288w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-556-300x42.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-556-1024x143.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-556-768x107.png 768w\" sizes=\"auto, (max-width: 1288px) 100vw, 1288px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1304\" height=\"840\" class=\"wp-image-15414\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-557.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-557.png 1304w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-557-300x193.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-557-1024x660.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-557-768x495.png 768w\" sizes=\"auto, (max-width: 1304px) 100vw, 1304px\" \/><\/p>\n<h2><strong>How to view Data from File Using Tail command with Different Options<\/strong><\/h2>\n<p>There are multiple ways to view data with the help tail command by using different options.<\/p>\n<p>Below are the options we can use with the tail command, and some of the options are explained with the help of examples.<\/p>\n<ul>\n<li>-n(number of lines)<\/li>\n<li>-c(number of bytes)<\/li>\n<li>-q(verbose)<\/li>\n<li>-f(follow<strong>)<\/strong><\/li>\n<\/ul>\n<h3><strong>How to use the tail command with \u2013n option <\/strong><\/h3>\n<p>The &#8220;-n&#8221; defines the number of lines to be printed on the screen starting from the end of the file. If the number is not supplied in the command, an error will be displayed. We can also write &#8216;-&#8216; with the number instead of the &#8216;n&#8217; character with this command.<\/p>\n<p>The below-mentioned command will display the last 5 lines of the &#8220;linux1.txt&#8221; file<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail -n 5 linux1.txt<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1287\" height=\"333\" class=\"wp-image-15415\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-558.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-558.png 1287w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-558-300x78.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-558-1024x265.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-558-768x199.png 768w\" sizes=\"auto, (max-width: 1287px) 100vw, 1287px\" \/><\/p>\n<h3><strong>How to use the tail command with \u2013c option <\/strong><\/h3>\n<p>The latest &#8216;&#8221;num&#8221; bytes from the provided file are printed. If the new line is counted as one character, it will be counted as a byte by the tail command if it is printed. It is required to type -c followed by any number, depending on the need. If there is a positive sign (&#8220;+&#8221;) before the number, it will be displayed by skipping the number of bytes from the beginning of the supplied file. If there is a negative sign (&#8220;-&#8220;) before the number, it displays the final number of bytes. If there is no &#8220;+&#8221; or &#8220;-&#8221; sign before the number, it will display the last number of bytes from the file supplied.<\/p>\n<p>The below-mentioned command will display the last 10 lines of the &#8220;linux1.txt&#8221; file. file.e<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail -c 10 linux1.tx<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1311\" height=\"246\" class=\"wp-image-15416\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-559.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-559.png 1311w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-559-300x56.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-559-1024x192.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-559-768x144.png 768w\" sizes=\"auto, (max-width: 1311px) 100vw, 1311px\" \/><\/p>\n<p>The below-mentioned command will display all data except the first 10 bytes of the &#8220;linux1.txt&#8221; file.<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail -c +10 linux1.txt<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1339\" height=\"593\" class=\"wp-image-15417\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-560.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-560.png 1339w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-560-300x133.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-560-1024x453.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-560-768x340.png 768w\" sizes=\"auto, (max-width: 1339px) 100vw, 1339px\" \/><\/p>\n<h3><strong>How to use the tail command with the \u2013q option <\/strong><\/h3>\n<p>If more than one file is specified, -q is used. As a consequence of this operation, the data from each file is not followed by the name of the file.<\/p>\n<p>The below-mentioned command will show the combined data of files &#8220;linux1.txt&#8221; and &#8220;linux2.txt&#8221; without specifying the file name, as it did in the output of &#8220;display data of multiple files&#8221; as shown above:<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail -q linux1.txt linux2.txt<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1306\" height=\"773\" class=\"wp-image-15418\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-561.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-561.png 1306w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-561-300x178.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-561-1024x606.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-561-768x455.png 768w\" sizes=\"auto, (max-width: 1306px) 100vw, 1306px\" \/><\/p>\n<h3><strong>How to use the tail command with the \u2013f option<\/strong><\/h3>\n<p>This option is mostly used by system administrators to keep track of the size of log files generated by various Unix programs as they run. This option displays the file&#8217;s last 10 lines and updates when new lines are added. When new lines are being written on the log, the console will refresh them. We must use the interrupt key or &#8220;Ctrl+Z&#8221; to abort this command because the prompt does not return even after work is completed. In general, error messages are written to log files by the apps. An error message is checked by it when it appears in the log file.<\/p>\n<p>The below-mentioned command will print the last 10 lines of linux1.txt, but the file will not be closed; it will prompt to write data or press Ctrl+Z to exit.<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail -f linux1.txt<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1320\" height=\"518\" class=\"wp-image-15419\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-562.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-562.png 1320w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-562-300x118.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-562-1024x402.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-562-768x301.png 768w\" sizes=\"auto, (max-width: 1320px) 100vw, 1320px\" \/><\/p>\n<h3><strong>How to use the tail command with the -v option<\/strong><\/h3>\n<p>When this option is used, data from the chosen file is always followed by the name of the file.<\/p>\n<p>The below-mentioned command will print the last 10 lines of linux1.txt followed by the filename &#8220;linux1.txt&#8221;:<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<pre><strong>$ tail -v linux1.txt<\/strong><\/pre>\n<\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1376\" height=\"473\" class=\"wp-image-15420\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-563.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-563.png 1376w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-563-300x103.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-563-1024x352.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/02\/word-image-563-768x264.png 768w\" sizes=\"auto, (max-width: 1376px) 100vw, 1376px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>There are many ways to display data from a file; in this article, we discussed how we can view data with the help of the tail command. By default, it displays the last 10 lines from the specified file, but by using different options we can change the display of data by using the tail command. All these options are discussed in detail with examples in this article. After going through this article, you can get a hands-on tail command to display data from the file.<\/p>","protected":false},"excerpt":{"rendered":"<p>There are many ways to display data from files and one of them is by using the &#8220;tail command&#8221;. This article is all about seeing data with the&hellip;<\/p>","protected":false},"author":1,"featured_media":15549,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,891,5,83,165,2],"tags":[759,647],"class_list":["post-15411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-manjaro","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-data","tag-tail-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/15411","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=15411"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/15411\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/15549"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=15411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=15411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=15411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}