How to Create an Empty Text File in the Ubuntu Terminal Using the touch Command

If you are accustomed to graphical desktop environments, creating a new file is usually as simple as right-clicking on your desktop and selecting “New Document.” However, when managing an Ubuntu server or working extensively in the command line, you do not have access to these graphical menus. You need a fast, reliable way to generate files directly from the prompt.

While you could use a text editor like Nano or Vim to create and save a new file, opening an entire text editor just to generate an empty placeholder is slow and inefficient. The fastest and most standard method for creating an empty file in Linux is using the touch command.

This guide explains how to use the touch command to create single files, multiple files simultaneously, and how to verify they were created successfully in Ubuntu.

The Basic touch Command

The primary purpose of the touch command is actually to change the timestamps on existing files (updating their “last modified” or “last accessed” times). However, it has a built-in secondary function: if you use touch on a file that does not currently exist, Linux will immediately create an empty file with that exact name.

To create a standard text file in your current directory, open your terminal (Ctrl + Alt + T) and type:

touch newfile.txt

Press Enter. The command will execute silently, returning you immediately to the prompt without displaying a confirmation message. The file newfile.txt now exists, containing zero bytes of data.

Creating Files with Specific Extensions

In Linux, file extensions (like .txt, .html, or .py) are not strictly required by the operating system, but they are incredibly helpful for organisation. The touch command does not care what extension you use; it will create whatever you tell it to.

For example, if you are setting up a new web project, you can quickly generate an HTML file, a CSS stylesheet, and a Python script by typing:

touch index.html
touch style.css
touch script.py

Creating Multiple Files Simultaneously

If you need to generate dozens of empty files at once, typing the command repeatedly is tedious. Fortunately, touch accepts multiple arguments. You can create several files simultaneously by simply separating their names with a space:

touch file1.txt file2.txt file3.txt

For even more advanced generation, you can use bash brace expansion to create sequentially numbered files. For example, to create ten configuration files numbered 1 through 10, use this command:

touch config_{1..10}.conf

This will instantly create config_1.conf, config_2.conf, and so on, up to config_10.conf.

Creating Files in Different Directories

By default, touch creates files in your current working directory. If you want to create a file in a different location without using the cd command to navigate there first, you can specify an absolute or relative path.

For example, to create a hidden file inside a user’s configuration folder, you would run:

touch ~/.config/myapp/.hidden_settings

Note: The target directory (in this case, ~/.config/myapp/) must already exist. The touch command cannot create missing parent directories; it can only create the file itself.

How to Verify File Creation

Because the touch command is completely silent on success, it is good practice to verify that your files were actually created where you expect them to be.

Use the list (ls) command to view the contents of the directory:

ls -l

This will display a detailed list of all files, confirming your newly created files are present, owned by your user account, and have a size of exactly 0 bytes.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.