Linux Basic Commands

10. cat

cat Command in Linux

cat stands for "concatenate", but it’s commonly used to view the contents of a file.


πŸ”Ή Basic Syntax:

cat [options] filename

πŸ”Ή Most Common Uses & Examples:

βœ… 1. View contents of a file

cat file.txt

πŸ‘‰ Displays the content of file.txt in the terminal.


βœ… 2. Create a new file using cat

cat > newfile.txt

Then type your content:

Hello, this is a new file.

Press Ctrl + D to save and exit.


βœ… 3. Append content to an existing file

cat >> file.txt

Type new content and press Ctrl + D.


βœ… 4. Combine multiple files into one

cat file1.txt file2.txt > combined.txt

πŸ‘‰ Combines file1.txt and file2.txt into combined.txt.


βœ… 5. Show line numbers

cat -n file.txt

πŸ‘‰ Displays the file with line numbers:

     1  This is line 1
     2  This is line 2

πŸ”Ή Summary Table:

Task

Command

View file

cat file.txt

Create file

cat > file.txt

Append file

cat >> file.txt

Combine files

cat file1 file2 > newfile

Line numbers

cat -n file.txt



Try with Linux Practice