FactorPad
Build a Better Process

Linux cat Command Summary with Examples

Linux cat allows us to sent input to output.
  1. Purpose - Learn what cat is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with cat.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux cat, 10 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / cat-command.html


An ad-free and cookie-free website.


Examples of the Linux cat Command

Beginner

Learn to send input to output at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux cat Command Summary with Examples (3:55)

Video Script

The Command and Why You Need It

Our tenth word, or command to memorize is cat from the category Text.

cat allows you to send input to output. In our last video we wanted to see available bash programs and here the cat command will solve that by sending a file as output to the screen.

Common Linux cat Options
-options description
-n Number the lines of output

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The cat command has 12 options and arguments are inputs of two types: files or text input to the keyboard. I'll show you both, and in one example we'll use this option -n to number the output lines.

A quick comment about input/ouput, there are three terms to remember all with default behavior here in our interactive shell. First, standard input is from the keyboard. Stantard output goes to the screen and standard error also goes to the screen.

So why is cat an important command? Well, cat is the easiest way to send text to the screen. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go, so cat is similar to less from video 5, except less is more like a word processor. cat instead just prints to the screen. So let's use the file from video 5 and output it with line numbers.

$ cat -n video5.txt 1 This is the first line 2 This is the second line 3 This is the thrid line 4 This is the fourth line 5 This is the fifth line 6 7 # A file for video 5 on less to demonstrate the -N option

Good. Now, try this, type cat and Enter.

$ cat _

The shell is waiting for you to type something in standard input. Type anything (and Enter).

$ cat anything anything _

Notice how it sits there, waiting for more?

$ cat anything anything What are you waiting for? What are you waiting for? _

If you are done, use Ctrl-c to stop the process.

$ cat anything anything What are you waiting for? What are you waiting for? ^C $ _

And last, let's tackle that problem from the last video. Type cat /etc/shells and look, it outputs a file listing 5 shells to the screen.

$ cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/dash /bin/bash /bin/rbash /usr/bin/tmux

A Final Tip

Okay now you know how to use cat. And you know the syntax for commands, options and arguments.

One last tip about the cat command. It's easy to write standard output to a file instead of the screen, and I'll show you that next.

Okay, thanks for visiting today. I hope this was a fun introduction to the cat command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Have questions? Subscribe and leave a note on YouTube. Follow @factorpad on Twitter for updates. Also, check out our no-spam email list.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / cat-command.html


linux cat command
linux cat examples
cat linux
cat command
cat unix
unix cat
cat command linux
cat file
cat linux command
linux contatenate files
shell cat
cat terminal
cat text
linux cat terminal
linux cat tutorial

A newly-updated free resource. Connect and refer a friend today.