If you are working in the Linux terminal and need to create a new configuration file, a script, or a blank text document, you could open a heavy text editor like nano or vim, type nothing, and save it. However, that is entirely unnecessary. The fastest and most efficient way to instantly generate a blank file in Linux is by using the built-in touch command.
Using the Touch Command
The touch command was originally designed to simply update the “last modified” timestamp on an existing file. However, if you run it on a file name that does not exist yet, it will instantly create a completely empty, 0-byte file with that exact name.
- Open your terminal application.
- Use the following command syntax:
touch filename.txt - Press Enter.
The terminal will instantly return to a blank prompt without displaying any success message. If you type ls -l, you will see your brand new, empty file waiting in the directory.
Creating Multiple Files at Once
The best part about the touch command is that it accepts multiple arguments. If you are setting up a new web project and need to quickly generate the HTML, CSS, and JavaScript files, you can do it all in a single line:
touch index.html style.css script.js
Press Enter, and all three blank files will be created instantly in your current directory.