If you are 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, so this is a common request for beginners. Manipulating text in Linux is essential to 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 preinstalled on Ubuntu-based Linux systems. It is a simple 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:
- If you don’t have the Nano text editor, download it here.

- Open a new terminal window by holding down “Control + Alt + T”.

- Type “nanoexample.txt” and press Enter. Replace “example” with whatever name you want for your text file.

- At the bottom of the window, you will find the “Command List”. Press “Control + G” to see all commands. These will help you create the new text file.

- Write your text document using the keyboard and the commands in the command list.

- Press “Control + O” to save the file.

- To return to the command prompt and exit Nano, press and hold “Control + X.”

Use Vim
With 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:
- If you still don’t have PushDownload and install it.

- Press “Control + Alt + T” to open a new terminal window.

- Type “vim example.txt” and press the Enter key. Replace “example” with the name you chose for the file.

- Tap the “I” key to open Vim in “Command Mode”. The word “Insert” appears at the bottom of the window.

- Now that you are in Vim’s “Insert Mode”, you can write your text document.

- Press the Esc key to return to “Command Mode.”

- To save your file, type “:w” and then press the Enter key.

- To return to the command prompt and exit 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 is a useful way to quickly create and save a text file.
- Open a new terminal window by pressing “Control + Alt + T”.

- Type “$cat > example.txt” and press the Enter button,
Replace the word “example” with the name you want to use for the file.
- Write the text you want to the file.

- Press the Return key and then press “Control + D.” This will tell Linux that you have added all the text. The usual command prompt will appear.

- To make sure your text file has been saved, type “$ls” and you will see the newly saved file.
Use touch command
Another way to quickly create a text file in Linux is to use the Touch command. However, by using this method, you will not be able to enter the text of the file when you create it. Using this method is most beneficial when you want to create multiple text files at the same time. For illustrative purposes, we will show you how to create multiple text files simultaneously. This is how you do it:
- Hold down “Control + Alt + T” to open a new command window.

- For example, if you want to create three new text files, type “$touch example1.txt example2.txt example3.txt” and replace the word “example” with the file names you want to use.

- Press the Enter key to save the files.

- You can check to make sure the files have been saved by typing “$ls”.

Now that you’ve created several text files with the Touch command, you’ll want to add text to them. This will need to be done using a text editor. We will use Nano for this example.
- Type “$nano example.txt” and replace the word “example” with the name of the file you created.

- Press the Enter button.

- From here, you can type the required text. Once you’re done, hold down “Control + X” and press the Enter key.
Creating text files in Linux solved
Creating a text file in Linux can be accomplished using several different methods. You can use the Touch or Cat commands within Linux from the terminal prompt. Alternative methods require text editors such as Vim or Nano, typically pre-built into most Ubuntu-based Linux systems.