The cat command is used for:
-
Displaying a text file
cat filename
If you would like to display all files in the current directory, use the wildcard
*like this:cat *To view all files or:
cat *.txtTo view all
.txtfiles only. -
Reading a text file
Sometimes a file will be too large to read since it won't fit on screen and will scroll by at high speed. To bypass this, use the
catcommand withmoreorless(however, on some shells the more command is not supported).cat bigfile | moreor
cat bigfile | less -
Creating a new text file
To create a file named "test.txt":
cat > test.txtThen, type the text you want to save into your file and press Ctrl + D when you are finished.
-
File concatenation (adding files)
To combine to files and create a new file called "newfile.txt":
cat file1.txt file2.txt > newfile.txt -
Modifying files
To add data to an existing file named "test.txt":
cat >> test.txtThen type your text, and again, press Ctrl + D when finished.