13 Basic Cat Command Examples in Linux

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

36 Responses

  1. Francesco Bertoldi says:

    How can I append an md-file to another md-file in a sub-folder? I tried “cat %U >> subfolder-name/%u“, but I get this error message “cannot create subfolder-name//path/to/md-file/md-file.md: Directory nonexistent“.

    Can you help me?

  2. pathan meeravali says:

    Very useful for my exams . Thank you.

  3. Leonardo says:

    Hi @Ravi,

    This is a really good stuff for beginners, like me by the way. About cat command, I have a quite different question: When I use that within a bash shell script that captures and display some output, how do I close the command processing? I mean, after running the script, I needed to press Enter or type Ctrl+C / Ctrl+D, and I would like to have the script terminated after the run.

    the lines I’ve entered in my script are:

    echo `cat | ls -ltr > temp3_mask_000`
    echo `cat | du -a >> temp3_mask_000`

    Thank you anyway for this teaching!

    • Ravi Saive says:


      At the end of your shell script, set exit 0 to close the shell script as shown.

      echo `cat | ls -ltr > temp3_mask_000`
      echo `cat | du -a >> temp3_mask_000`
      # Terminate our shell script with success message
      exit 0
  4. doesn't matter says:

    #ZombieRessurection – please do not spread bad practices

    cat | more file” is not smart as “cat file file | sort > newfile” isn’t
    less file
    sort file file > newfile

    for selecting rows comfortable use sed instead:

    sed -n '4,6p' file

    will print lines 4-6 from

  5. Jacob says:

    Sir I am a Linux newbie, can you please say the ways to learn all Linux commands.

  6. Arun says:

    12. Redirecting Multiple Files Contain in a Single File

    still the type in contain

  7. Kent says:

    Thanks. Just a little help about spelling of a word used frequently. “Contains”. I think you want “Contents”.

    • Ravi Saive says:


      Oops what a big mistake and was not realized or pointed by anyone so far, thanks a ton Kent for notifying us, we’ve replaced the word contains with content in the writeup..really thankful to you..

  8. dan says:

    will you teach me how to do this on windows please

    • Ravi Saive says:


      You mean on Windows 10 with Bash on it? If you have Bash installed on your Windows, all cat command examples shown here will work without any errors..

  9. Chandra says:

    Hi Ravi thanks.

    How can I select lines (i.e. rows) 10 to line 15 from a given file, let, ABC.txt, using cat command:

    Suppose I use the following command for getting the first 20 lines and 10 columns of the file ABC.txt which contains a table

    $ cat ABC.txt | head -20| cut -f1-10 

    Looking forward.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.