The cat command is a standard Unix program used to concatenate and display files. The name is from catenate, a synonym of concatenate.
cat
- concatenate files and print on the standard output.
The cat
command is used for:
- Display text file on screen
- Read text file
- Create a new text file
- File concatenation
- Modifying file
Example
$ cat -n file #shows the content of a file, including the line-numbers(-n flag)
Concatenating two files into third file:
cat file1 file2 > 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"
A common interactive use of cat for a single file is to output the content of a file to standard output. If the output is piped or redirected, cat is unnecessary.
Without two named files, the use of cat has no significant benefits.