The cat command in the terminal is short for "concatenate" and is primarily used to display the contents of files. It can also be used to combine multiple files into one. Here are some common uses of the cat command:
-
Display the contents of a file:
cat filename.txtThis command will output the entire contents of
filename.txtto the terminal. -
Combine multiple files:
cat file1.txt file2.txt > combined.txtThis command concatenates
file1.txtandfile2.txtand saves the result incombined.txt. -
Create a new file:
You can use
catto create a new file by redirecting the output:cat > newfile.txtAfter running this command, you can type text, and when you press
CTRL + D, it will save the text tonewfile.txt. -
View file contents with line numbers:
cat -n filename.txtThis command displays the contents of
filename.txtwith line numbers.
The cat command is a versatile tool for file manipulation and viewing in the terminal.
