Exploring Cat Command in Linux

Updated: Feb 4

Cat command is used to concatenate files and to view the contents of files on the standard output in Linux. The following 15 examples can help you understand how to use Linux cat command.

Display a File Using cat

The cat command displays a file to the screen.

cat filename

Cat Command with More & Less Options

cat filename|more
cat filename|less

Show Line Numbers using Cat

For all the non-empty lines in a file use the following command:

cat -b filename

If there are lines with no characters at all they won't be numbered. To show numbers for all the lines regardless as to whether they are blank, type the following command:

cat -n filename

Display non-printing characters using Cat

cat -e filename

Reducing Blank Lines with Cat

When you show the contents of a file using the cat command you probably don't want to see when there are loads of consecutive blank lines. Use the -s switch to condense all blank lines into a single blank line:

cat -s filename

Copy the contents of one file to another

cat filename > filename-new

Appending the contents of one file to another

cat filename >> filename-new

View the contents of many files with Cat

cat filename1 filename2 filename3

Redirecting the output of multiple files into a single file

cat filename1 filename2 filename3 > filename-new

Sorting Contents of Multiple Files in a Single File

cat filename1 filename2 filename3|sort > filename-new


Join our newsletter. Get a free Linux account on Cloud.

Get a Free Cloud Server! 

We can use this cloud server to practice Linux commands. Never miss a post!

Thanks for submitting!