Exploring cat - Linux Commands
- #linux
What is the cat Command in Linux?
The cat command stands for concatenate. It is used to read, concatenate, and write the contents of files to the standard output (usually the terminal). It is one of the most commonly used commands in Linux for viewing file contents.
Basic syntax:
cat [option] [file]
Example:
cat file-name
Common cat Use Cases
Viewing a Single File
cat filename.txt
Concatenating Multiple Files
You can combine the contents of multiple files into a new file using the > operator.
cat file1.txt file2.txt > combined.txt
Appending to an Existing File
Use the >> operator to append text or file contents to the end of an existing file.
cat new-data.txt >> existing-data.txt
cat Command Options
| Option | Description |
|---|---|
| -A, --show-all | Equivalent to -vET, showing non-printing characters (except for spaces and tabs), end of lines, and tabs |
| -b, --number-nonblank | Number all non-empty output lines |
| -E, --show-ends | Display a dollar sign $ at the end of each line |
| -n, --number | Number all output lines |
| -s, --squeeze-blank | Suppress repeated empty output lines |
| -T, --show-tabs | Display TAB characters as ^I |
| -v, --show-nonprinting | Use ^ and M- notation, except for LFD and TAB characters |
Additional Help
You can explore more by using the commands:
cat --help
# or
man cat
Thank you
Thank you for your time and for reading this!