The Stack Overflow podcast is back! Listen to an interview with our new CEO.

cat is a standard Unix utility used for concatenating files or printing specific file on the standard output.

cat is a standard Unix utility used for concatenating files or printing specific file on the standard output.

The cat program is given files in a sequence as arguments, it will output their contents to the standard output in the same sequence.

Examples

Printing the contents of a file on the standard output.

cat -n file.txt # n stands for line-numbers

Concatenating two files into third file:

cat file1.txt file2.txt > output_file

The purpose of cat is to concatenate (or catenate) files. If it is only one file, concatenating it with nothing at all is a waste of time, and costs you a process. This is also referred to as "cat abuse".

Nevertheless the following usage is common:

cat filename | command arg1 arg2 argn    
cat -- "$file" | grep -- "$pattern"
cat -- "$file" | less

can instead be written as:

grep -- "$pattern" "$file"
less "$file"

Further reading

history | excerpt history