The cat command in Bash has several useful applications beyond just displaying file contents. Here are some common uses:
-
Concatenate Files: You can combine multiple files into one. For example:
cat file1.txt file2.txt > combined.txtThis command merges
file1.txtandfile2.txtintocombined.txt. -
Create a New File: You can create a new file and write content to it:
cat > newfile.txtAfter running this command, you can type your content and press
Ctrl + Dto save it. -
Append to a File: You can add content to an existing file:
cat >> existingfile.txtThis allows you to append text to
existingfile.txt. -
Display Line Numbers: You can display the contents of a file with line numbers:
cat -n file.txt -
View Multiple Files: You can view the contents of multiple files sequentially:
cat file1.txt file2.txt
These are just a few examples of how versatile the cat command can be. If you have more questions or need further details, feel free to ask!
