{"id":679,"date":"2018-08-01T21:51:17","date_gmt":"2018-08-01T21:51:17","guid":{"rendered":"http:\/\/hyderabadwebhosting.in\/blog\/?p=679"},"modified":"2018-08-01T22:14:51","modified_gmt":"2018-08-01T22:14:51","slug":"view-contents-of-file-in-linux","status":"publish","type":"post","link":"https:\/\/hyderabadwebhosting.in\/blog\/view-contents-of-file-in-linux\/","title":{"rendered":"Manage Files Effectively using head, tail and cat Commands in Linux"},"content":{"rendered":"<p><strong><em><span style=\"font-size: large;\">Manage Files Effectively using head, tail and cat Commands in Linux<\/span><\/em><\/strong><\/p>\n<p><span style=\"font-size: large;\">There are several commands and programs provided by Linux for viewing the contents of file. Working with files is one of the daunting task, most of the computer users be it newbie, regular user, advanced user, developer, admin, etc performs. Working with files effectively and efficiently is an art.<\/span><\/p>\n<p><strong><span style=\"font-size: large;\">1. head Command<\/span><\/strong><\/p>\n<p><span style=\"font-size: large;\">The head command reads the first ten lines of a any given file name. The basic syntax of head command is:<\/span><\/p>\n<p><span style=\"font-size: large;\">head [options] [file(s)]<\/span><\/p>\n<p><span style=\"font-size: large;\">For example, the following command will display the first ten lines of the file named \u2018\/etc\/passwd\u2018.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-681 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/1-1.png\" alt=\"\" width=\"643\" height=\"187\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/1-1.png 643w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/1-1-300x87.png 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">If more than one file is given, head will show the first ten lines of each file separately. For example, the following command will show ten lines of each file.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/2-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-683 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/2-1.png\" alt=\"\" width=\"782\" height=\"419\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/2-1.png 782w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/2-1-300x161.png 300w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/2-1-768x411.png 768w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/2-1-660x354.png 660w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">If it is desired to retrieve more number of lines than the default ten, then \u2018-n\u2018 option is used along with an integer telling the number of lines to be retrieved. For example, the following command will display first 5 lines from the file \u2018\/var\/log\/yum.log\u2018 file.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/3-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-684 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/3-1.png\" alt=\"\" width=\"642\" height=\"105\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/3-1.png 642w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/3-1-300x49.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">In fact, there is no need to use \u2018-n\u2018 option. Just the hyphe<\/span><span style=\"font-size: large;\">n and specify the integer without spaces to get the same result as the above command.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-685 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/4.png\" alt=\"\" width=\"644\" height=\"106\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/4.png 644w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/4-300x49.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">The head command can also display any desired number of bytes using \u2018-c\u2018 option followed by the number of bytes to be displayed. For example, the following command will display the first 45 bytes of given file.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/5-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-686 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/5-1.png\" alt=\"\" width=\"645\" height=\"54\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/5-1.png 645w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/5-1-300x25.png 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/a><\/p>\n<p><strong><span style=\"font-size: large;\">2. tail Command<\/span><\/strong><\/p>\n<p><span style=\"font-size: large;\">The tail command allows you to display last ten lines of any text file. Similar to the head command above, tail command also support options \u2018n\u2018 number of lines and \u2018n\u2018 number of characters.<\/span><\/p>\n<p><span style=\"font-size: large;\">The basic syntax of tail command is:<\/span><\/p>\n<p><span style=\"font-size: large;\"># tail [options] [filenames]<\/span><\/p>\n<p><span style=\"font-size: large;\">For example, the following command will print the last ten lines of a file called \u2018boot.log\u2018.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/6-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-687 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/6-1.png\" alt=\"\" width=\"642\" height=\"178\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/6-1.png 642w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/6-1-300x83.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/p>\n<p><strong><span style=\"font-size: large;\">3. cat Command<\/span><\/strong><\/p>\n<p><span style=\"font-size: large;\">The \u2018cat\u2018 command is most widely used, universal tool. It copies standard input to standard output. The command supports scrolling, if text file doesn\u2019t fit the current screen.<\/span><\/p>\n<p><span style=\"font-size: large;\">The basic syntax of cat command is:<\/span><\/p>\n<p><span style=\"font-size: large;\"># cat [options] [filenames] [-] [filenames]<\/span><\/p>\n<p><span style=\"font-size: large;\">The most frequent use of cat is to read the contents of files. All that is required to open a file for reading is to type cat followed by a space and the file name.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/7-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-688 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/7-1.png\" alt=\"\" width=\"911\" height=\"578\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/7-1.png 911w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/7-1-300x190.png 300w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/7-1-768x487.png 768w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/7-1-660x419.png 660w\" sizes=\"auto, (max-width: 911px) 100vw, 911px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">The cat command also used to concatenate number of files together.<\/span><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/8-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-690 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/8-2.png\" alt=\"\" width=\"641\" height=\"71\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/8-2.png 641w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/8-2-300x33.png 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/9-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-691 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/9-1.png\" alt=\"\" width=\"647\" height=\"24\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/9-1.png 647w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/9-1-300x11.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/10-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-692 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/10-1.png\" alt=\"\" width=\"648\" height=\"82\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/10-1.png 648w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/07\/10-1-300x38.png 300w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">It can be also used to create files as well. It is achieved by executing cat followed by the output redirection operator and the file name to be created.<\/span><\/p>\n<p>&nbsp;<\/p>\n<div class=\"pdf24Plugin-cp\"> \t<form name=\"pdf24Form0\" method=\"post\" action=\"https:\/\/doc2pdf.pdf24.org\/wordpress.php\" target=\"pdf24PopWin\" onsubmit=\"var pdf24Win = window.open('about:blank', 'pdf24PopWin', 'resizable=yes,scrollbars=yes,width=600,height=250,left='+(screen.width\/2-300)+',top='+(screen.height\/3-125)+''); pdf24Win.focus(); if(typeof pdf24OnCreatePDF === 'function'){void(pdf24OnCreatePDF(this,pdf24Win));}\"> \t\t<input type=\"hidden\" name=\"blogCharset\" value=\"Cw1x07UAAA==\" \/><input type=\"hidden\" name=\"blogPosts\" value=\"MwQA\" \/><input type=\"hidden\" name=\"blogUrl\" value=\"yygpKSi20tfPqExJLUpMSkwpT03KyC8uycxL18vM00\/KyU8HAA==\" \/><input type=\"hidden\" name=\"blogName\" value=\"86hMSS1KTEpMUQhPTVLwyC8uycxLBwA=\" \/><input type=\"hidden\" name=\"blogValueEncoding\" value=\"gzdeflate base64\" \/><input type=\"hidden\" name=\"postId_0\" value=\"MzO3BAA=\" \/><input type=\"hidden\" name=\"postTitle_0\" value=\"DcbBDYAgDAXQVf4AbmH0pEP8QMEmpRwKRrfXd3onnVWwq0lgK0XS0FvsxQz1ikuYFwyqgZ6ROLD21v4H1HGoz+cD\" \/><input type=\"hidden\" name=\"postLink_0\" value=\"BcHBDYAwCADAiZC\/2xRLCwkBI2h1e++k6swdUb7OV6PWF5NElvrc1JEsJj7KC47wYq+EGDDUGNTB1O8Xfw==\" \/><input type=\"hidden\" name=\"postAuthor_0\" value=\"c\/QLDVAICHJ08XD0AwA=\" \/><input type=\"hidden\" name=\"postDateTime_0\" value=\"MzIwtNA1ACJDBSNDKwMLK0NzAA==\" \/><input type=\"hidden\" name=\"postContent_0\" value=\"tVrLjts2FN33KwgXKBLAtixbtuyJZ4CiaIAU7aoFugiyoCXaJiKRqkj5kVU\/o\/29fkkPScnvSTxjepGJZYn3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jb17Z+HrL2NsBwENKMdYc48fXIWB8hIDxK5q52ra6ZuwkmaDk0qzOHlSRNctcEW1+hpAs7RsJU3axDUsq+9OJ04LMFGGunkb5lqKyS2xTzPwggmrUdGeFWt0Pc57POrUHSP4f\" \/> \t\t<a href=\"https:\/\/www.pdf24.org\" target=\"_blank\" title=\"www.pdf24.org\"><img src=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/plugins\/pdf24-post-to-pdf\/img\/sheep_32x32.png\" alt=\"www.pdf24.org\" border=\"0\" height=\"32\" \/><\/a> \t\t<span class=\"pdf24Plugin-cp-space\">&nbsp;&nbsp;<\/span> \t\t<span class=\"pdf24Plugin-cp-text\">Send article as PDF<\/span> \t\t<span class=\"pdf24Plugin-cp-space\">&nbsp;&nbsp;<\/span> \t\t<input class=\"pdf24Plugin-cp-input\" style=\"margin: 0px;\" type=\"text\" name=\"sendEmailTo\" placeholder=\"Enter email address\" \/> \t\t<input class=\"pdf24Plugin-cp-submit\" style=\"margin: 0px;\" type=\"submit\" value=\"Send\" \/> \t<\/form> <\/div>","protected":false},"excerpt":{"rendered":"<p>Manage Files Effectively using head, tail and cat Commands in Linux There are several commands and programs provided by Linux for viewing the contents of file. Working with files is one of the daunting task, most of the computer users be it newbie, regular user, advanced user, developer, admin, etc performs. Working with files effectively\u2026 <span class=\"read-more\"><a href=\"https:\/\/hyderabadwebhosting.in\/blog\/view-contents-of-file-in-linux\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-679","post","type-post","status-publish","format-standard","hentry","category-vps"],"_links":{"self":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":3,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"predecessor-version":[{"id":693,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions\/693"}],"wp:attachment":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}