How to Create an Empty File Using the Touch Command in Ubuntu Linux

In the Linux environment, particularly when working within the terminal, you frequently need to create new files before writing data to them. Whether you are creating a placeholder log file, a new configuration script, or simply testing permissions, the fastest and most efficient way to generate a completely blank file in Ubuntu Linux is by using the touch command.

What Does the Touch Command Actually Do?

Historically, the primary purpose of the touch command was to change the access and modification timestamps of an existing file (literally “touching” the file to update its timestamp without opening it). However, a secondary feature of the command has become its most popular use: if you tell touch to update the timestamp of a file that does not exist yet, it will automatically create that file as a completely empty, 0-byte document.

How to Create a Single Empty File

Creating a file requires only the command and your desired filename.

  1. Open your terminal in Ubuntu.
  2. Navigate to the directory where you want the file to live using the cd command.
  3. Type the following command: touch filename.txt

If you run the ls -l command to list your files, you will see filename.txt has been created instantly with a file size of exactly 0 bytes.

How to Create Multiple Files Simultaneously

One of the major advantages of the terminal over a graphical file manager is the ability to create multiple items at once. You can pass multiple filenames to the touch command separated by spaces.

touch file1.txt file2.log script3.sh

All three files will be generated instantly in the current directory.

How to Create Files in a Different Directory

You do not need to navigate into a folder to create a file inside it. You can simply provide the absolute or relative path to the destination directory.

touch /var/log/custom_app/error_log.txt

Note: If you are creating a file in a system directory (like /var/log), you will need to prefix the command with sudo to grant the necessary administrator permissions (e.g., sudo touch /var/log/test.log).

What Happens if the File Already Exists?

It is crucial to understand that the touch command is non-destructive. If you accidentally run touch important_document.txt, and that document already exists and contains data, it will not overwrite or delete your data. It will simply update the file’s modification timestamp to the current clock time, leaving the contents entirely untouched.

Get the best tech tips delivered straight to your inbox.

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