Ubuntu Linux: Create a Text File Using cat Command

by on January 9, 2011 · 1 comment· LAST UPDATED June 9, 2013

in , ,

How can I create a text file from the command line on Ubuntu Linux? How do I create an empty file from the command line under Ubuntu operating systems?

You can use the following commands:

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementscat/bash shell
Estimated completion timeLess than a 1 minute
cat > fileName - Create a text file.

> fileName - Create an empty file.

touch fileName - Create an empty file.

Example - Create an empty file

Open a terminal and type the following command to create a file called foo.txt:

> foo.txt


touch foo.txt

To verify your file, enter:

ls -l foo.txt
cat foo.txt

Example - Create a text file

Open a terminal and type the following cat command to create a text file called bar.txt:

cat > bar.txt

Add text or lines:

This is a test.
To swap out hard drive as an external storage you need to use

You need to press [CTRL] + [D] i.e. hold the control key down, then tap d. The > symbol tells the Ubuntu that what is typed is to be stored into the file called bar.txt. To verify your data, enter:

ls -l bar.txt
cat bar.txt
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 Buvanesh Kumar January 25, 2014 at 6:35 pm

hey very wonderful. Thank you. i am new in Ubuntu. i love Ubuntu. i want more this type of Terminal tutorials. Please send to mailto:buvanesh@engineer.com


Leave a Comment

Tagged as: , ,

Previous Faq:

Next Faq: