{"id":1861,"date":"2021-10-05T18:15:15","date_gmt":"2021-10-05T12:45:15","guid":{"rendered":"https:\/\/coimbatorewebhosting.com\/blog\/?p=1861"},"modified":"2022-01-22T15:44:07","modified_gmt":"2022-01-22T10:14:07","slug":"top-13-basic-cat-commands-in-linux","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/","title":{"rendered":"Top 13 Basic Cat Commands in Linux"},"content":{"rendered":"<p>In this article, we are going to find out the handy use of <strong>cat<\/strong> commands with their examples in <a href=\"https:\/\/www.redhat.com\/en\" target=\"_blank\" rel=\"noopener nofollow\">Linux<\/a>.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"1664\" data-permalink=\"https:\/\/www.webhostingchennai.co.in\/blog\/13-basic-cat-commands-in-linux\/13-basic-cat\/\" data-orig-file=\"https:\/\/i2.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/13-basic-cat.jpg?fit=640%2C260&amp;ssl=1\" data-orig-size=\"640,260\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"13 basic cat\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i2.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/13-basic-cat.jpg?fit=300%2C122&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/13-basic-cat.jpg?fit=640%2C260&amp;ssl=1\" loading=\"eager\" class=\"alignnone wp-image-1664 size-full jetpack-lazy-image jetpack-lazy-image--handled\" src=\"https:\/\/i2.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/13-basic-cat.jpg?resize=640%2C260\" alt=\"13 Basic Cat Commands in Linux\" data-recalc-dims=\"1\" srcset=\"https:\/\/i2.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/13-basic-cat.jpg?w=640&amp;ssl=1 640w, https:\/\/i2.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/13-basic-cat.jpg?resize=300%2C122&amp;ssl=1 300w\" data-lazy-loaded=\"1\" sizes=\"(max-width: 640px) 100vw, 640px\" width=\"640\" height=\"260\" \/><\/p>\n<p>The <strong>cat<\/strong> (short for \u201c<strong>concatenate<\/strong>\u201c) command is one of the most frequently used commands in Linux\/Unix-like operating systems. <strong>cat<\/strong> command allows us to create single or multiple files, view content of a file, concatenate files and redirect output in terminal or files.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#General_Syntax_of_Cat_Command\" >General Syntax of Cat Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#1_Display_Contents_of_File\" >1. Display Contents of File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#2_View_Contents_of_Multiple_Files_in_terminal\" >2. View Contents of Multiple Files in terminal<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#3_Create_a_File_with_Cat_Command\" >3. Create a File with Cat Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#4_Use_Cat_Command_with_More_Less_Options\" >4. Use Cat Command with More &amp; Less Options<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#5_Display_Line_Numbers_in_File\" >5. Display Line Numbers in File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#6_Display_at_the_End_of_File\" >6. Display $ at the End of File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#7_Display_Tab_Separated_Lines_in_File\" >7. Display Tab Separated Lines in File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#8_Display_Multiple_Files_at_Once\" >8. Display Multiple Files at Once<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#9_Use_Standard_Output_with_Redirection_Operator\" >9. Use Standard Output with Redirection Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#10_Appending_Standard_Output_with_Redirection_Operator\" >10. Appending Standard Output with Redirection Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#11_Redirecting_Standard_Input_with_Redirection_Operator\" >11. Redirecting Standard Input with Redirection Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#12_Redirecting_Multiple_Files_Contain_in_a_Single_File\" >12. Redirecting Multiple Files Contain in a Single File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-13-basic-cat-commands-in-linux\/#13_Sorting_Contents_of_Multiple_Files_in_a_Single_File\" >13. Sorting Contents of Multiple Files in a Single File<\/a><\/li><\/ul><\/nav><\/div>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"General_Syntax_of_Cat_Command\"><\/span>General Syntax of Cat Command<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre>$ cat [OPTION] [FILE]...<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"1_Display_Contents_of_File\"><\/span>1. Display Contents of File<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The below example will show the <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-configure-pop3-imap-email-account-in-thunderbird\/\" title=\"contents\" alt=\"contents\">contents<\/a> of <strong>\/etc\/passwd<\/strong> file.<\/p>\n<pre># cat \/etc\/passwd\r\n\r\nroot:x:0:0:root:\/root:\/bin\/bash\r\nbin:x:1:1:bin:\/bin:\/sbin\/nologin\r\nnarad:x:500:500::\/home\/narad:\/bin\/bash<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"2_View_Contents_of_Multiple_Files_in_terminal\"><\/span>2. View Contents of Multiple Files in terminal<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In below example, it will display the contents of the <strong>test<\/strong> and <strong>test1<\/strong> file in the terminal.<\/p>\n<pre># cat test test1\r\n\r\nHello everybody\r\nHi world,<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"3_Create_a_File_with_Cat_Command\"><\/span>3. Create a File with Cat Command<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>We will create a file called <strong>test2<\/strong> file with the below command.<\/p>\n<pre># cat &gt;test2<\/pre>\n<p><center><\/center><\/p>\n<div id=\"tecmint_incontent\" data-google-query-id=\"CNq2iunIofMCFUhqKwodcN4IBg\" align=\"center\">\n<div id=\"google_ads_iframe_\/15184186,18758028\/tecmint_incontent_0__container__\">\n<div class=\"__fs-ancillary\">\n<div class=\"__fs-branding\">Awaits input from the user, type desired text, and press <strong>CTRL+D<\/strong> (hold down <strong>Ctrl key<\/strong> and type \u2018<strong>d<\/strong>\u2018) to exit. The text will be written the <strong>test2<\/strong> file. You can see the content of the file with the following <strong>cat<\/strong> command.<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<pre># cat test2\r\n\r\nhello everyone, how do you do?<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"4_Use_Cat_Command_with_More_Less_Options\"><\/span>4. Use Cat Command with More &amp; Less Options<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>If a file having a <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/enable-customize-php-fpm-directives\/\" title=\"large number\" alt=\"large number\">large number<\/a> of content that won\u2019t fit in the output terminal and the screen scrolls up very fast, we can use parameters more and less with the <strong>cat<\/strong> command as shown below.<\/p>\n<pre># cat song.txt | more\r\n# cat song.txt | less<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"5_Display_Line_Numbers_in_File\"><\/span>5. Display Line Numbers in File<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>With the <strong>-n<\/strong> option you could see the line numbers of a file <strong>song.txt<\/strong> in the output terminal.<\/p>\n<pre># cat -n song.txt\r\n\r\n1  \"Heal The World\"\r\n2  There's A Place In\r\n3  Your Heart\r\n4  And I Know That It Is Love\r\n5  And This Place Could\r\n6  Be Much\r\n7  Brighter Than Tomorrow\r\n8  And If You Really Try\r\n9  You'll Find There's No Need\r\n10  To Cry\r\n11  In This Place You'll Feel\r\n12  There's No Hurt Or Sorrow<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"6_Display_at_the_End_of_File\"><\/span>6. Display $ at the End of File<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In the below, you can see with the <strong>-e<\/strong> option that \u2018<strong>$<\/strong>\u2018 is shows at the end of the line and also in space showing \u2018<strong>$<\/strong>\u2018 if there is any gap between paragraphs. This option is useful to squeeze multiple lines into a single line.<\/p>\n<pre># cat -e test\r\n\r\nhello everyone, how do you do?$\r\n$\r\nHey, am fine.$\r\nHow's your training going on?$\r\n$<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"7_Display_Tab_Separated_Lines_in_File\"><\/span>7. Display Tab Separated Lines in File<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In the below output, we could see <strong>TAB<\/strong> space is filled up with the \u2018<strong>^I<\/strong>\u2018 characters.<\/p>\n<pre># cat -T test\r\n\r\nhello <strong>^I<\/strong>everyone, how do you do?\r\n\r\nHey, <strong>^I<\/strong>am fine.\r\n<strong>^I<\/strong>^IHow's your training <strong>^I<\/strong>going on?\r\nLet's do <strong>^I<\/strong>some practice in Linux.<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"8_Display_Multiple_Files_at_Once\"><\/span>8. Display Multiple Files at Once<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In the below example we have three files <strong>test<\/strong>, <strong>test1,<\/strong> and <strong>test2,<\/strong> and able to view the contents of those <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/using-an-external-mail-server-in-direct-admin\/\" title=\"files\" alt=\"files\">files<\/a> as shown above. We need to separate each file with <strong>;<\/strong> (semicolon).<\/p>\n<pre># cat test; cat test1; cat test2\r\n\r\nThis is a test file\r\nThis is the test1 file.\r\nThis is test2 file.<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"9_Use_Standard_Output_with_Redirection_Operator\"><\/span>9. Use Standard Output with Redirection Operator<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>We can redirect the standard output of a file into a new file else existing file with a \u2018<strong>&gt;<\/strong>\u2018 (greater than) symbol. Careful, existing contents of the <strong>test1<\/strong> will be overwritten by the contents of the <strong>test<\/strong> file.<\/p>\n<pre># cat test &gt; test1<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"10_Appending_Standard_Output_with_Redirection_Operator\"><\/span>10. Appending Standard Output with Redirection Operator<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Appends in existing file with \u2018<strong>&gt;&gt;<\/strong>\u2018 (double greater than) symbol. Here, the contents of the <strong>test<\/strong> file will be appended at the end of the <strong>test1<\/strong> file.<\/p>\n<pre># cat test &gt;&gt; test1<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"11_Redirecting_Standard_Input_with_Redirection_Operator\"><\/span>11. Redirecting Standard Input with Redirection Operator<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>When you use the redirect with standard input \u2018<strong>&lt;<\/strong>\u2018 (less than symbol), it uses file name <strong>test2<\/strong> as input for command and output will be shown in a terminal.<\/p>\n<pre># cat &lt; test2\r\n\r\nThis is test2 file.<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"12_Redirecting_Multiple_Files_Contain_in_a_Single_File\"><\/span>12. Redirecting Multiple Files Contain in a Single File<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>This will create a file called <strong>test3<\/strong> and all output will be redirected in a newly created file.<\/p>\n<pre># cat test test1 test2 &gt; test3<\/pre>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"13_Sorting_Contents_of_Multiple_Files_in_a_Single_File\"><\/span>13. Sorting Contents of Multiple Files in a Single File<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>This will create a file <strong>test4<\/strong> and the output of the <strong>cat<\/strong> command is piped to sort and the result will be redirected to a newly created file.<\/p>\n<pre># cat test test1 test2 test3 | sort &gt; test4<\/pre>\n<p>This article shows the basic commands that may help you to explore the <strong>cat<\/strong> commands.<\/p>\n<p>To know more about memory usage on centos server <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-check-memory-usage-on-centos-server\/\">click here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to find out the handy use of cat commands with their examples in Linux. The cat (short for \u201cconcatenate\u201c) command is one of the most frequently used commands in Linux\/Unix-like operating systems. cat command allows us to create single or multiple files, view content [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1886,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[153,17,3,1],"tags":[],"class_list":["post-1861","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-7-rhel-7","category-general","category-linux","category-latest"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2021\/10\/13basiccommands.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-u1","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1861"}],"version-history":[{"count":3,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1861\/revisions"}],"predecessor-version":[{"id":1888,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1861\/revisions\/1888"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/1886"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}