cat Command: Read and Combine File Contents in Linux

The cat command short for concatenate, It is a fast and versatile tool for viewing and merging file contents directly from the Linux terminal. Whether you’re inspecting logs or quickly joining multiple text files, cat delivers what you need with efficient simplicity.

How cat Works

You use cat to display the contents of files. Simply run:

cat filename.txt

You’ll instantly see everything written in the file printed to your screen. If you want to review the contents of several files at once, list them in sequence:

cat filename1.txt filename2.txt filename3.txt

The result is that cat outputs all three files’ data in order.

Basic Syntax

cat [OPTION] [FILE]
  • [OPTION]: Command-line options to modify output
  • [FILE]: The target file(s) for processing

Common cat Command Uses

1. View a Single File

Display file content directly:

cat report.txt

2. View Multiple Files

Show the contents of files in succession:

cat intro.txt summary.txt

3. Show File with Line Numbers

Make each line identifiable for reviews or troubleshooting:

cat -n server.log

4. Create a New File

Quickly create and populate a file by typing text followed by Ctrl+D to save:

cat > notes.txt

5. Copy or Merge Files

Merge multiple files into a new one:

cat part1.txt part2.txt > merged.txt

6. Squeeze Blank Lines

Suppress repeated empty lines in output:

cat -s messy.txt

7. Append to an Existing File

Add content to the end of a file:

cat changelog.txt >> history.txt

8. Highlight End of Lines

Show the $ at the end of every line for clarity:

cat -E notes.txt

9. All Text Files at Once

Display all text files in a folder:

cat *.txt

Useful cat Command Options

OptionUsage
-AShow all characters, including non-printing
-bNumber only non-empty lines
-EDisplay $ at end of every line
-nNumber all lines
-sSqueeze multiple adjacent blank lines
-TShow tabs as ^I
-vMake non-printing characters visible
-uUnbuffered output (rarely needed)

Conclusion

From viewing a small config file to merging hundreds of logs for analysis, cat is a fundamental Linux skill that increases productivity at the terminal. Its versatility means every user, whether new or advanced benefits from mastering it.

Read More: History of Linux

0xSnow

0xSnow is a cybersecurity researcher with a focus on both offensive and defensive security. Working with ethical hacking, threat detection, Linux tools, and adversary simulation, 0xSnow explores vulnerabilities, attack chains, and mitigation strategies. Passionate about OSINT, malware analysis, and red/blue team tactics, 0xSnow shares detailed research, technical walkthroughs, and security tool insights to support the infosec community.

Recent Posts

How Web Application Firewalls (WAFs) Work

General Working of a Web Application Firewall (WAF) A Web Application Firewall (WAF) acts as…

3 weeks ago

How to Send POST Requests Using curl in Linux

How to Send POST Requests Using curl in Linux If you work with APIs, servers,…

3 weeks ago

What Does chmod 777 Mean in Linux

If you are a Linux user, you have probably seen commands like chmod 777 while…

3 weeks ago

How to Undo and Redo in Vim or Vi

Vim and Vi are among the most powerful text editors in the Linux world. They…

3 weeks ago

How to Unzip and Extract Files in Linux

Working with compressed files is a common task for any Linux user. Whether you are…

3 weeks ago

Free Email Lookup Tools and Reverse Email Search Resources

In the digital era, an email address can reveal much more than just a contact…

3 weeks ago