CAT Cheat Sheet
Here’s an advanced cheat sheet for the cat
command, including some useful options and examples:
Basic Usage:
cat filename
: Display the content of a file.
Advanced Options:
- Numbering Lines:
-n
: Number all output lines.-b
: Number non-empty output lines. Example:
cat -n file.txt
- Display Non-Printable Characters:
-v
: Display non-printable characters as visible representations. Example:
cat -v file.txt
- Suppress Output:
-s
: Suppress repeated empty output lines. Example:
cat -s file.txt
- Concatenate Multiple Files:
- Concatenate and display the content of multiple files. Example:
cat file1.txt file2.txt
- Display $ at End of Lines:
-e
: Display a $ character at the end of each line. Example:
cat -e file.txt
- Display Tabs as ^I:
-T
: Display tab characters as ^I. Example:
cat -T file.txt
- Display Line Endings:
-E
: Show line endings as $. Example:
cat -E file.txt
- Output to Another File:
- Redirect the output of
cat
to another file. Example:
cat file.txt > newfile.txt
- Append to a File:
- Append the output of
cat
to an existing file. Example:
cat file.txt >> existingfile.txt
- Combine with Other Commands:
- Use
cat
in combination with other commands using pipes (|
) for complex operations.
cat file.txt | grep "pattern"
- Use
Remember, with great power comes great responsibility! Make sure to use these advanced options wisely and responsibly.