Linux – cat Command

The cat command stands for “concatenate.” It is commonly used to display the contents of files, combine multiple files into one, or create new files.



Tutorials dojo strip

Initial Example

Using cat to display the contents of a file called example.txt:

cat example.txt




CAT Parameters

ParameterDescription
-A, --show-allEquivalent to -vET, show all non-printing characters, ends of lines, and tabs as special characters
-b, --number-nonblankNumber only non-empty output lines, overriding -n
-eEquivalent to -vE, show non-printing characters and display $ at the end of each line
-E, --show-endsDisplay $ at the end of each line to indicate line endings
-n, --numberNumber all output lines, including empty ones
-s, --squeeze-blankSuppress repeated empty output lines and display just one
-tEquivalent to -vT, show non-printing characters and tabs as ^I
-T, --show-tabsDisplay TAB characters as ^I
-uIgnored, retained for compatibility
-v, --show-nonprintingDisplay non-printing characters using ^ and M- notation, except for LFD and TAB
--helpDisplay help information and exit
--versionShow version information and exit




Examples

1. Display the Contents of a File

To view the contents of a file:

cat filename.txt

2. Display the Contents of Multiple Files

To view the contents of multiple files sequentially:

cat file1.txt file2.txt

3. Combine Multiple Files into One

To concatenate the contents of multiple files and save them into a new file:

cat file1.txt file2.txt > combined.txt

4. Append the Contents of a File to Another File

To append the contents of one file to the end of another file:

cat file1.txt >> file2.txt

5. Create a New File with Text Input

To create a new file and add text to it (press Ctrl+D to save and exit):

cat > newfile.txt
This is the content of the new file.
Ctrl+D

6. Display Line Numbers

To display the contents of a file with line numbers:

cat -n filename.txt

7. Display Non-Printing Characters

To display the contents of a file while showing non-printing characters:

cat -v filename.txt




Linux Playground

Scroll to Top