Back to course

18. Creating Empty Files: The `touch` Command

Linux Basics: From Zero to CLI Hero

Generating Files Quickly

The touch command is primarily used to change the access and modification timestamps of a file. However, if the specified file doesn't exist, touch will create it as an empty file.

Creating a Single File

bash $ touch notes.txt $ ls -l notes.txt -rw-r--r-- 1 user user 0 Nov 7 14:45 notes.txt

Note the size is 0 bytes

Creating Multiple Files

bash $ touch script1.sh script2.sh config.ini

Using touch for Timestamps (Advanced)

If the file does exist, touch updates its timestamp to the current time. This is useful for triggering rebuilds in automated systems or seeing when a file was last modified.

bash $ touch existing_file.log