When working in the Linux terminal, you will frequently find yourself in situations where you need to create a brand-new file from scratch. While you could open a text editor like nano or vim, type nothing, and then save the file, this is incredibly slow. System administrators rely on a tiny, lightning-fast utility called touch to instantly generate empty files.
Why Do You Need an Empty File?
Creating a file with absolutely zero bytes of data inside it sounds pointless, but it is actually a core part of Linux system administration. You might need to create a blank configuration file before installing a new web server, or generate a dummy log file to prevent a poorly written automated script from crashing because it cannot find the file it expects to write to.
How to Use the touch Command
Using the command is incredibly simple. Open your terminal and type touch followed by the name of the file you want to create, including the extension.
touch config.php
Press Enter. The terminal will immediately drop down to a blank line without any success message. However, if you type ls -l to list the contents of the directory, you will see your new config.php file sitting there, perfectly blank, with a file size of exactly 0 bytes.
You can even create multiple files simultaneously by separating the names with a space:
touch index.html style.css script.js
The Hidden Secondary Use of touch
The touch command was actually designed for a completely different purpose, which is where it gets its name. It was designed to “touch” a file to update its timestamps.
In Linux, every file tracks the exact date and time it was last modified. If you have an existing file (let’s say, backup.zip) that was created three months ago, and you run the touch command on it:
touch backup.zip
It will not delete or overwrite the contents of the zip file. Instead, it simply updates the file’s “Last Modified” timestamp to the exact current time on the server. This is frequently used by server administrators to trick backup software into thinking an old file is brand new, forcing the backup system to copy it again during the next nightly run.