touch – Create New Empty File

The touch command is a Linux command used to create a new empty file in the specified location. It is a simple yet powerful command that is frequently used by Linux system administrators.

Overview

To create a new empty file using the touch command, simply type touch followed by the name of the file you want to create. For example, to create a file named newfile.txt, type the following command:

touch newfile.txt

If the file already exists, the touch command will update the timestamp of the file to the current time.

Use Cases

  • Creating a new file: touch newfile.txt
  • Updating the timestamp of an existing file: touch existingfile.txt
  • Creating multiple files at once: touch file1.txt file2.txt file3.txt

Options

The touch command has several options that can be used to customize its behavior. The available options are listed in the table below:

Option Description
-a Change the access time of the file only
-c Do not create the file if it does not exist
-d Use a specific date and time instead of the current time
-m Change the modification time of the file only
-r Use the timestamp of another file
-t Use a specific timestamp instead of the current time

To use an option, simply type it before the name of the file. For example, to change the access time of a file named myfile.txt, use the following command:

touch -a myfile.txt

Troubleshooting tips

If you encounter issues while using the touch command, here are some troubleshooting tips:

  • If you receive a “permission denied” error, make sure you have the necessary permissions to create or modify files in the specified location.
  • If the file already exists and you want to update its timestamp, make sure you have write permissions for the file.

Notes

  • The touch command can also be used to update the timestamp of a directory. However, this will not create any new files or directories within the specified directory.