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 12 This is line 2
πΉ Summary Table:
|
Task |
Command |
|---|---|
|
View file |
|
|
Create file |
|
|
Append file |
|
|
Combine files |
|
|
Line numbers |
|
Try with Linux Practice