PROGRAMS

# cat

Article by:

## Overview

cat (short for concatenate), is a basic terminal-based Linux program for manipulating text-based files. It is commonly used to quickly output the contents of a text file to the screen, so that you can read it without having to open an editor.

Some of the following examples use .txt file extensions to indicate they contain textual information, but remember that this is optional, there is no notion of a “file extension” in Linux.

 1  $cat >>filename.txt  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.  1  $ cat /dev/null > filename.txt 

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

## To Output Line Numbers

Use the -n switch.

 1  $cat -n filename.txt  ## Append/Concatenate Files To Another You can use redirection (>) to append the contents of one file into another.  1  $ cat file1 > file 2 

You can list multiple files all at one to concatenate them into a single output file.

 1  \$ cat file1 file2 file3 > file4 

## Authors

### Geoffrey Hunter

Dude making stuff.