{"id":1861,"date":"2021-10-05T18:15:15","date_gmt":"2021-10-05T12:45:15","guid":{"rendered":"https:\/\/coimbatorewebhosting.com\/blog\/?p=1861"},"modified":"2021-10-05T18:15:15","modified_gmt":"2021-10-05T12:45:15","slug":"top-13-basic-cat-commands-in-linux","status":"publish","type":"post","link":"https:\/\/tiruppurwebhosting.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\">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<h4 class=\"fittexted_for_content_h4\">General Syntax of Cat Command<\/h4>\n<pre>$ cat [OPTION] [FILE]...<\/pre>\n<h4 class=\"fittexted_for_content_h4\">1. Display Contents of File<\/h4>\n<p>The below example will show the contents of <strong>\/etc\/passwd<\/strong> file.<\/p>\n<pre># cat \/etc\/passwd\n\nroot:x:0:0:root:\/root:\/bin\/bash\nbin:x:1:1:bin:\/bin:\/sbin\/nologin\nnarad:x:500:500::\/home\/narad:\/bin\/bash<\/pre>\n<h4 class=\"fittexted_for_content_h4\">2. View Contents of Multiple Files in terminal<\/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\n\nHello everybody\nHi world,<\/pre>\n<h4 class=\"fittexted_for_content_h4\">3. Create a File with Cat Command<\/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\n\nhello everyone, how do you do?<\/pre>\n<h4 class=\"fittexted_for_content_h4\">4. Use Cat Command with More &amp; Less Options<\/h4>\n<p>If a file having a large number 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\n# cat song.txt | less<\/pre>\n<h4 class=\"fittexted_for_content_h4\">5. Display Line Numbers in File<\/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\n\n1  \"Heal The World\"\n2  There's A Place In\n3  Your Heart\n4  And I Know That It Is Love\n5  And This Place Could\n6  Be Much\n7  Brighter Than Tomorrow\n8  And If You Really Try\n9  You'll Find There's No Need\n10  To Cry\n11  In This Place You'll Feel\n12  There's No Hurt Or Sorrow<\/pre>\n<h4 class=\"fittexted_for_content_h4\">6. Display $ at the End of File<\/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\n\nhello everyone, how do you do?$\n$\nHey, am fine.$\nHow's your training going on?$\n$<\/pre>\n<h4 class=\"fittexted_for_content_h4\">7. Display Tab Separated Lines in File<\/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\n\nhello <strong>^I<\/strong>everyone, how do you do?\n\nHey, <strong>^I<\/strong>am fine.\n<strong>^I<\/strong>^IHow's your training <strong>^I<\/strong>going on?\nLet's do <strong>^I<\/strong>some practice in Linux.<\/pre>\n<h4 class=\"fittexted_for_content_h4\">8. Display Multiple Files at Once<\/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 files as shown above. We need to separate each file with <strong>;<\/strong> (semicolon).<\/p>\n<pre># cat test; cat test1; cat test2\n\nThis is a test file\nThis is the test1 file.\nThis is test2 file.<\/pre>\n<h4 class=\"fittexted_for_content_h4\">9. Use Standard Output with Redirection Operator<\/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\">10. Appending Standard Output with Redirection Operator<\/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\">11. Redirecting Standard Input with Redirection Operator<\/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\n\nThis is test2 file.<\/pre>\n<h4 class=\"fittexted_for_content_h4\">12. Redirecting Multiple Files Contain in a Single File<\/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\">13. Sorting Contents of Multiple Files in a Single File<\/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","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 of a file, concatenate files<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[148,92,9,149],"tags":[],"class_list":["post-1861","post","type-post","status-publish","format-standard","hentry","category-centos-7-rhel-7","category-general","category-linux","category-latest"],"_links":{"self":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1861"}],"version-history":[{"count":0,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1861\/revisions"}],"wp:attachment":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}