Linux

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:

  1. Numbering Lines:
  • -n: Number all output lines.
  • -b: Number non-empty output lines. Example:
   cat -n file.txt
  1. Display Non-Printable Characters:
  • -v: Display non-printable characters as visible representations. Example:
   cat -v file.txt
  1. Suppress Output:
  • -s: Suppress repeated empty output lines. Example:
   cat -s file.txt
  1. Concatenate Multiple Files:
  • Concatenate and display the content of multiple files. Example:
   cat file1.txt file2.txt
  1. Display $ at End of Lines:
  • -e: Display a $ character at the end of each line. Example:
   cat -e file.txt
  1. Display Tabs as ^I:
  • -T: Display tab characters as ^I. Example:
   cat -T file.txt
  1. Display Line Endings:
  • -E: Show line endings as $. Example:
   cat -E file.txt
  1. Output to Another File:
  • Redirect the output of cat to another file. Example:
   cat file.txt > newfile.txt
  1. Append to a File:
  • Append the output of cat to an existing file. Example:
   cat file.txt >> existingfile.txt
  1. Combine with Other Commands:
    • Use cat in combination with other commands using pipes (|) for complex operations.
    Example: cat file.txt | grep "pattern"

Remember, with great power comes great responsibility! Make sure to use these advanced options wisely and responsibly.