cat

Overview

cat (short for concatenate), is a basic terminal-based Linux program for manipulating text-based files.

All of the following examples use .txt file extensions, but remember that this is optional, there is no notion of a “file extension” in Linux.

To Create A File

Now type the text you want in the file. Press CTRL-D to exit and save the file. Warning: This will overwrite pre-existing files.

Output A File To The Screen

This basic command will print the contents of the text file to the terminal.

To Append To A File

Now type the text you want in the file. Press CTRL-D to exit and save the file. Warning: This will overwrite pre-existing files.

Empty A File

This trick works by redirecting the null output to your file, which clears it’s contents.

Warning: This will delete all the contents of a file, without prompt.

To Output Line Numbers

Use the -n switch.

Posted: July 8th, 2014 at 1:03 pm
Last Updated on: April 27th, 2017 at 4:42 am