How To Create a Text File in Linux

If you’re new to Linux, you may want to learn how to create a text file. Experienced Linux users know the importance of learning how to create text files, which is why this is a common request for beginners. Manipulating text in Linux is essential in mastering its full functionality. Fortunately, it’s relatively easy to learn.


This article will show you a few different ways to quickly create a text file in Linux. In most cases, you can use a text editor or the command line within Linux.

Use Nano

Nano is a popular text editor that usually comes pre-installed with Ubuntu-based Linux systems. It’s a straightforward and easy-to-use editor. There are other text editors for Linux, but Nano is the most beginner friendly. To create a text file using Nano, follow these steps:

  1. If you don’t have the Nano text editor, download it here.
  2. Open a new terminal window by holding down “Control + Alt + T”.
  3. Type “nano example.txt” and hit Enter. Replace “example” with the name you want for your text file.
  4. At the bottom of the window, you’ll find the “Command List.” Press “Control + G” to see all of the commands. These will assist you while creating the new text file.
  5. Type in your text document using the keyboard and commands from the command list.
  6. Press “Control + O” to save the file.
  7. To return to the command prompt and exit Nano, hold down “Control + X”.

Use Vim

Using the Vim text editor, you can also create a Linux text file. Most Ubuntu-based Linux systems come with Vim already installed. Vim is similar to Nano. The main difference is that it has more features and a steeper learning curve. To use this method to create a text file, do the following:

  1. If you don’t already have Vim, download and install it.
  2. Press “Control +Alt + T” to open a new terminal window.
  3. Type “vim example.txt” and hit the Enter key. Replace “example” with the name you’ve chosen for the file.
  4. Tap the “I” key to open Vim in “Command Mode.” The word “Insert” appears at the bottom of the window.
  5. Now that you’re in Vim’s “Insert Mode,” you can type in your text document.
  6. Press the Esc key to take you back to “Command Mode.”
  7. To save your file, type “:w” and then hit the Enter key.
  8. To return to the command prompt and leave Vim, type “:q” and press Enter.

Use the Cat Command

If you prefer not to use a text editor, you can create a text file in Linux using the Cat command. It’s a helpful way to create and save a text file quickly.

  1. Open a new terminal window by pressing “Control + Alt + T”.
  2. Type in “$ cat > example.txt” and hit the Enter button,
    Replace the word “example” with the name you’d like to use for the file.
  3. Type in the text you’d like in the file.
  4. Press the Return key and then press “Control + D”. This will tell Linux that you’ve added all the text. The usual command prompt will appear.
  5. To ensure that your text file was saved, type “$ ls” and you’ll see the newly saved file.

Use the Touch Command                                      

Another way to quickly create a text file in Linux is to use the Touch command. However, when using this method, you won’t be able to enter the text for the file when you create it. Using this method is most beneficial when you want to make multiple text files at the same time. For illustrative purposes, we’ll show you how to create multiple text files simultaneously. Here’s how it’s done:

  1. Hold down “Control + Alt + T” to open a new command window.
  2. For example, if you’d like to create three new text files, type in “$ touch example1.txt example2.txt example3.txt” and replace the word “example” with the file names you’d like to use.
  3. Hit the Enter key to save the files.
  4. You can check to ensure that the files have been saved by typing in “$ ls”.

Now that you’ve created multiple text files using the Touch command, you’ll want to add text to them. This will need to be done using a text editor. We’ll use Nano for this example.

  1. Type in “$ nano example.txt” and replace the word “example” with the name of the file you created.
  2. Hit the Enter button.
  3. From here, you can type in the required text. Once you’ve finished, hold down “Control + X” and hit the Enter key.

Creating Text Files in Linux Solved

Creating a text file in Linux can be accomplished using several different methods. You can utilize the Touch or the Cat commands within Linux from the terminal prompt. Alternate methods require text editors such as Vim or Nano, typically prebuilt into most Ubuntu-based Linux systems.

Have you tried to create a text file in Linux? Did you use one of the methods outlined in this article? Let us know in the comments section below.