Linux for Developers Course
Linux for Developers
/
Beginner

cat

Definition

Concatenate. A command used to read data from a file and output its entire contents directly to the terminal screen.

Explain Like I'm New

The 'Print this file to the screen' command. It dumps all the text out at once.

Real World Example

You want to quickly check the IP address in a config file. You type `cat config.txt`. The text of the file is dumped onto your terminal screen so you can read it.

Common Use Cases

  • •Reading small files
  • •Combining (concatenating) multiple files into one

Crucial Command Flags

Flag / OptionDescription
-nNumber all output lines.
-bNumber non-empty output lines.
-EDisplay $ at the end of each line.
-sSqueeze multiple empty lines into one.

Interview Questions

basic

  • Why is it a bad idea to use `cat` on a massive 10GB log file?

intermediate

  • How do you use `cat` to combine `file1.txt` and `file2.txt` into a brand new `file3.txt`?

Flash Cards

Question

Why bad for large files?

Click to reveal answer
Answer

Because `cat` dumps the entire file at once. It will violently scroll thousands of lines of text across your screen, freezing the terminal, and you won't be able to read any of it.

Question

How to combine?

Click to reveal answer
Answer

Using the redirect operator: `cat file1.txt file2.txt > file3.txt`.