FactorPad
Faster Learning Tutorials

Linux cat command summary with examples

cat allows you to send 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.
Paul Alan Davis, CFA, October 7, 2016
Updated: July 26, 2018
In this tutorial, 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 Next

~/ home  / technology  / linux essentials  / cat command


The Linux cat command

Beginner

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

Video Tutorial

Linux cat command summary with examples (3:55)

Videos can also be accessed from the YouTube Playlist.

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.

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 in YouTube.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the bash command, hit Back.
  • To learn how to find commands and print output to a file instead of the screen with the type command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / cat command



 
 
Keywords:
linux cat command
cat linux
linux concatenate
linux standard input
linux standard ouput
linux standard error
linux print to screen
combine text in linux
combine files in linux
unix cat
cat text
cat terminal
shell cat
cat file
linux cat tutorial