Linux Command - cat
cat - concatenate and print files to stdout
cat file1.txt # print contents of file
cat file1.txt file2.txt # print contents of multiple files
cat file1.txt > file2.txt # overwrite file2.txt with file1.txt
cat file1.txt >> file2.txt # append instead of overwrite
cat one two > combined # combine 2 files into 1
cat test1.txt | grep test # pipe output, filter with grep
cat test1.txt | wc -l # pipe output, count lines
| -A | show all ( same as -vET ) |
| -b | number non-empty output lines ( override -n ) |
| -e | same as vE |
| -E | show ends ( $ at end of line ) |
| -n | number all output lines |
| -s | squeeze blank, filter out blank, repeated lines |
| -t | same as -vT |
| -T | show tabs |
| -v | show non printing characters |
You can write multiple lines to a file like this. It will read in what ever you type, line at a time until you type [CTRL]-D.
cat > test1.txt
Line of text.
Another line of text.
CTRL-D
You can use the following to read in text line at a time until it encounters EOF. It will then create/write/overwrite the file.
cat << EOF > test1.txt
Line of text.
Another line of text.
EOF