Ubuntu Linux: Create a Text File Using cat Command

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:

ADVERTISEMENTS

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementscat/bash shell
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

OR

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 
^D

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
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
5 comments… add one
  • Buvanesh Kumar Jan 25, 2014 @ 18:35

    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

  • NotARobot Sep 6, 2016 @ 18:55

    cool, i thought that the text file would be like press word or something that would pop up and u can start type in it

  • Devacann Feb 11, 2017 @ 19:39

    Nice….. now i know how create a empty file somewhere in the universe.

  • salty May 31, 2017 @ 1:37

    okay… and where do you find the file you created? not a very big help if it gets lost in the code after i created it….

    • 🐧 Vivek Gite May 31, 2017 @ 5:41

      Run ls command:
      ls
      OR
      find $HOME -iname "your-file-name-here"

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.