Skip to content

Using the ‘cat’ command to create a file

December 28, 2010

As a way to read the command and comments easily I have created a little legend…

The prompt will be in black like :-


The commands will be in orange, the arguments will be in  pink, and the specific file I am working with will be in pink and underlined like : –

ls -l file.txt

The Comments will start with a # and will be in italics, these are my personal comments and are not supposed to be typed into the command line unless specified in the text, the comments are just for illustration only, and will be in blue like : –

## Example of a comment that aids in the understanding of the concept at the time

So all in all, when I am trying to show a command in a command line interface, it will look something like this: –

prompt>ls -l file.txt ## Example of a comment that aids in the understanding of the concept at the time


Now onwards with the ‘cat’ command!

In Linux Operating Systems the ‘cat’ command is normally used to print the contents of a file from start to finish on the command line interface being used.

E.g.: –

prompt>cat file.txt

## below the contents of the file has been printed by hitting the return carriage the command and arguments typed in the above prompt

prompt>cat file.txt
As you can see this is the printed content from the file labelled file.txt

An interesting argument I have learned has enabled me to create files by using the ‘cat‘ command with a few arguments, namely ‘>‘. Basically the ‘cat‘ command can be used to create a file with a string of characters to form as data being stored in the file.

e.g. the below example creates a file called “number1.txt” with the following content ‘I do not know why I am Number 1’: –

prompt>cat > number1.txt
I do not know why I am Number 1          ### Once I have typed what I wanted to save in this file, then I save the changes to the file and exit by pressing ctrl+d on my keyboard
[1]+  Stopped                 cat > number1.txt          ### This line shows that using the ‘cat’ command I have successfully created number1.txt

The above arguments to the command ‘cat’ I think will prove useful when I need to create files quickly and edit them, on the other hand you can use text editors like vi, nano, etc to create files and save the strings of characters to the specific file too.


From → Linux

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: