How to Create an Empty File in Ubuntu Terminal

When working in a visual operating system like Windows, creating a new file is intuitive: you right-click the desktop, select “New,” and choose “Text Document.” When you are managing a Linux server entirely through a text-based terminal, the process requires a specific command.

While you could open a heavy text editor like Nano or Vim, save a blank document, and close the editor again, this is incredibly inefficient. Linux provides a much faster, dedicated utility designed specifically to generate empty files instantly.

The ‘touch’ Command

The touch command was originally designed to modify the timestamp of an existing file (making the system believe it was edited today). However, it has a secondary, highly useful function: if you use the touch command on a file name that does not exist yet, it immediately creates it as a perfectly blank, 0-byte file.

  1. Open your terminal or SSH into your Ubuntu server.
  2. Navigate to the directory where you want the file to live (e.g., cd /home/user/documents).
  3. Type the word touch, followed by a space, followed by your desired filename and extension. Then press Enter:
touch server-notes.txt

The terminal will instantly return a blank prompt. The file has been created. If you type the ls command to list the directory contents, you will see server-notes.txt sitting there, ready to be populated with data later.

How to Create Multiple Empty Files Simultaneously

One of the massive advantages of using the command line over a visual interface is speed. If you need to generate five empty files to structure a new programming project, doing it visually takes several minutes of right-clicking. With the touch command, you can do it in one second.

Simply list all the filenames you want to create, separated by a single space:

touch index.html style.css script.js config.json

Ubuntu will process the command and instantly generate all four empty files in the current directory simultaneously.

How to Create a Hidden File

In Linux, a “hidden” file is simply any file that has a name starting with a period (a dot). These files are ignored by standard directory lists and are typically used for configuration settings.

To create a hidden empty file, just add a period to the very beginning of the filename:

touch .secret-config.cfg

If you type ls, you will not see the file. You must type ls -a (list all) to reveal the hidden file you just created.

Get the best tech tips delivered straight to your inbox.

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