The cat command has several useful applications beyond simply displaying file contents. Here are some common uses:
-
Concatenating Files:
Combine multiple files into one.cat file1.txt file2.txt > combined.txt -
Creating a New File:
Create a new file and write content to it.cat > newfile.txt(Type your content and press
CTRL+Dto save.) -
Appending to a File:
Add content to the end of an existing file.cat >> existingfile.txt(Type your content and press
CTRL+Dto save.) -
Displaying Line Numbers:
Show line numbers along with the content.cat -n file.txt -
Displaying Non-Printable Characters:
Show non-printable characters in a file.cat -v file.txt -
Using with Pipes:
Combine with other commands using pipes.cat file.txt | grep "search_term" -
Redirecting Output:
Redirect output to another command or file.cat file.txt | sort > sortedfile.txt
These examples illustrate the versatility of the cat command in various scenarios.
