Cheat Sheet #day51 - cat

cat Command Cheatsheet
The cat command in Unix/Linux is used to concatenate and display the contents of files. It stands for "concatenate" and is commonly used to read and output file content. Below are the basic and advanced usages of the cat command along with practical examples.
Basic Usage
Display the contents of a file
cat filenameDisplay the contents of multiple files
cat file1 file2Concatenate multiple files and redirect the output to a new file
cat file1 file2 > newfile
Common Options
Number all output lines
cat -n filenameShow non-printing characters (except for tabs and the end of line)
cat -v filenameDisplay line ends with a
$signcat -E filenameDisplay tabs as
^Icat -T filenameSuppress repeated empty output lines
cat -s filename
Examples
Display a single file
cat file.txtDisplay multiple files
cat file1.txt file2.txtConcatenate files and write to a new file
cat file1.txt file2.txt > newfile.txtNumber all output lines
cat -n file.txtShow non-printing characters
cat -v file.txtDisplay line ends
cat -E file.txtDisplay tabs as
^Icat -T file.txtSuppress repeated empty lines
cat -s file.txt
Advanced Usage
Concatenate files and append to an existing file
cat file1.txt file2.txt >> existingfile.txtCreate a new file with
cat(end input withCtrl+D)cat > newfile.txt This is the content of the new file.Combine
catwith other commands using pipescat file.txt | grep "search_term"
Practical Tips
View Large Files: Use
catto quickly view the contents of large files, but consider usinglessormorefor easier navigation.Combine Files: Use
catto combine multiple files into a single file.Create Files: Use
catto create and quickly input content into new files.Use with Caution: Be careful with output redirection (
>) to avoid accidentally overwriting important files.
Quick Reference
Display file contents:
cat filenameNumber all output lines:
cat -n filenameShow non-printing characters:
cat -v filenameDisplay line ends:
cat -E filenameDisplay tabs as
^I:cat -T filenameSuppress repeated empty lines:
cat -s filenameConcatenate files:
cat file1 file2 > newfileAppend to an existing file:
cat file1 file2 >> existingfileCreate a new file:
cat > newfile.txt
This cheatsheet covers the essential commands and options for using cat effectively, from displaying file contents to concatenating and creating new files. Adjust the commands according to your specific requirements and environment.




