cat

file managementLinux/Unix
The cat command is one of the most frequently used commands in Linux/Unix-like operating systems. cat Concatenate and display files

Quick Reference

Command Name:

cat

Category:

file management

Platform:

Linux/Unix

Basic Usage:

cat filename.txt

Common Use Cases

  • 1

    Display file contents

    Quickly view small text files in the terminal

  • 2

    Concatenate files

    Combine multiple text files into a single file

  • 3

    Create new files

    Create small text files directly from the terminal

  • 4

    Append to files

    Add content to the end of existing files

Syntax

cat [OPTION]... [FILE]...

Options

Option Description
-n Number all output lines
-b Number non-empty output lines
-A Show all non-printable characters
-s Suppress repeated empty output lines
-T Display tab characters as ^I
-v Show non-printing characters using ^ and M- notation

Examples

How to Use These Examples

The examples below show common ways to use the cat command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

# Basic Examples
cat filename.txt
Display the contents of a file.
cat file1.txt file2.txt
Concatenate and display multiple files.
cat -n filename.txt
Display file contents with line numbers.
# Advanced Examples Advanced
cat > newfile.txt
Create a new file and write content to it.
cat file1.txt file2.txt > combined.txt
Combine multiple files into a new file.
cat file3.txt >> combined.txt
Append content to an existing file.
cat -A filename.txt
Display non-printing characters.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

These are sample notes for the cat command.

Tips & Tricks

1

Use cat with grep to search for text in files: cat file.txt | grep "search term"

2

Combine cat with wc to count lines: cat file.txt | wc -l

3

Use cat with sort to display file contents alphabetically: cat file.txt | sort

4

Display line numbers only for non-empty lines with cat -b

5

Use cat -A to reveal hidden characters like tabs and line endings

Common Use Cases

Display file contents

Quickly view small text files in the terminal

Concatenate files

Combine multiple text files into a single file

Create new files

Create small text files directly from the terminal

Append to files

Add content to the end of existing files

Display line numbers

Show file contents with line numbers for reference

Related Commands

grep

grep

View command

head

head

View command

tail

tail

View command

less

less

View command

more

more

View command

tac

tac

View command

tee

tee

View command

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the cat command works in different scenarios.

$ cat
View All Commands