cat has 3 related functions with regard to text files:
cat's general syntax is
cat [options] [filenames] [-] [filenames]
Display the contents of a file named file1:
cat file1
The standard output of cat is redirected using the output redirection operator (which is represented by a rightward pointing angular bracket) to file2:
cat file1 > file2
The output from cat is written to file2 instead of being displayed on the monitor screen. Write into a file:
cat > file
The following command will concatenate copies of the contents of the three files file1, file2 and file3 (display on screen):
cat file1 file2 file3
Redirection operator to another file, such as file4, using the following:
cat file1 file2 file3 > file4
In the next example, the output of cat is piped to the sort filter in order to alphabetize the lines of text after concatenation and prior to writing to file4:
cat file1 file2 file3 | sort > file4
A new file named file1 can be created by typing (or overwritten if file1 already exists):
cat > file1
Use append operator:
cat >> file1
To create a new file file6 that consists of text typed in from the keyboard followed by the contents of file5, first enter the following:
cat - file5 > file6
Or to create a new file file8 that consists of the contents of file7 followed by text typed in from the keyboard, first enter the following:
cat file7 - > file8