Linux cat Command

In this Linux tutorial you will learn how to use the Linux cat command. The Linux cat command is the Unix command to list a file’s contents onto your screen, or pass via pipeline to use with other Linux commands. The cat command comes from the word concatenate.

The usage of the Linux cat command is cat [options] [file].

There are quite a few options you can use with the Linux cat command, but I rarely use any of them on a regular basis. The only option I use with the cat command on a regular basis is cat -n or cat --number.

For an example of using the cat command, we’ll say I have a file named Linux-Friends.txt and in this text file I have some friend’s names, phone numbers, and e-mail addresses that run Linux. So now I want to get someone’s phone number from this list. I can run cat Linux-Friends.txt in a Linux terminal and I will get the contents of this file listed on my screen.

Now if I wanted to see how many friends I have listed in this file, I can have cat number the lines for me by using the cat -n option. So if I run cat -n Linux-Friends.txt the cat command will then output each of the Linux friend’s that I have listed and place a number in front of each one so I can see how many friends I have. Using cat -n [file] is also useful when doing some programming or coding, so you can see what line number you need to edit.

You can also pipe off of the Linux cat command to use it with other Linux commands. So for this example of the Linux cat command I want to only grab a certain person’s name from the list to display their contact information. So I can run cat Linux-Friends.txt|grep Brandon and now I will only get Brandon’s contact information.

Another example of using the Linux cat command with other Linux commands via pipe is if I only want Brandon’s email address to display and not his phone number. The Linux-Friends.txt file is in this format: last name, first name – phone number – email address so I can use the Linux cat command with grep and also awk to display only what I want. So I can run cat Linux-Friends.txt|grep Brandon|awk '{print $4" "$5}' and now I have Brandon’s phone number.

For an explaination of the command above I will show each output as each command is ran.
cat Linux-Friends.txt
–friend 1,2,3–
Stimmel, Brandon – (330) 222-7222 –
–friend 5,6,7–
Now we add |grep Brandon
Stimmel, Brandon – (330) 222-7222 –
and you see the other friends are now gone. Now we can add |awk '{print $4" "$5}' which will display the 4th and 5th column, and the – in that file counts as a column as well. The 4th column is (330) and the 5th column is 222-7222. So my output now would be: (330) 222-7222

I hope this has helped you learn how to use the Linux cat command in a Linux terminal and also using the cat command with other commands via pipeline. Remember to come back and visit Beginner Linux Tutorial for all of your Linux questions and tutorials. If there is a Linux tutorial you’d like to see on Beginner Linux Tutorial please let us know.

Comment Linux tutorial or Leave a Trackback


  1. jyoti baviskar
    Posted October 7, 2009 at 5:24 am | Linux tutorial comment

    its better for student to download linux free of cost
    so it really helped us

  2. Posted October 8, 2009 at 11:24 am | Linux tutorial comment

    Yes, Linux is free! Which is a lot better than having to pay $100 for Windows Vista, or $200 for Windows 7 especially with today’s economy, whether you are a student or just an everyday person. Money is tight, so save some money and download Linux for free!

  3. Anonymous
    Posted January 3, 2011 at 9:29 pm | Linux tutorial comment

    If money is an issue just get yourself a pirated version of Windows. I do this all the time and it works great!

  4. Posted January 4, 2011 at 12:50 am | Linux tutorial comment

    Yes there are pirated versions of Windows out there, but Linux is still more stable, faster, and more secure. So pirated version of Windows still won’t solve those issues.

    Plus for companies, they can’t use pirated versions of Windows.

  5. Christina Mello
    Posted February 4, 2011 at 8:44 pm | Linux tutorial comment

    whats the difference between cat and less?

  6. Posted February 6, 2011 at 11:58 pm | Linux tutorial comment

    the Linux cat command will display the entire file at once so if the file is 20 pages long you get the entire file at once. The Linux less command will display a page worth and you can scroll the rest by hitting enter.

  7. frank
    Posted June 27, 2011 at 9:38 am | Linux tutorial comment

    explanations simple but wonderful getting more interested in working with linux

  8. ANkush
    Posted August 4, 2011 at 4:25 am | Linux tutorial comment

    how to update a alredy created file???

  9. Posted August 11, 2011 at 11:17 pm | Linux tutorial comment

    You can edit files with vi, vim, pico, nano, gedit, kate, and tons more. Any text editor you like, whether it’s GUI or CLI. The ones I mentioned are usually packaged with most Linux distributions.

2 Trackbacks

  1. […] cat command- this command is used to print|view the contents of a file to the […]

  2. […] Linux commands more and less are similar to cat, but with more and less you can scroll the file instead of showing the enter file at once. So if […]

Post a Comment

Your email is never published nor shared. Required fields are marked *