touch Command: Tutorial & Examples
Create or modify files
The touch
command in Linux is a command-line utility used to create new, empty files or update the timestamp of existing files. The basic syntax of the command
is touch [options] file
.
When run with the name of a file that does not currently exist, touch creates a new, empty file with that name. For example, the command touch newfile.txt
will create a new,
empty file named newfile.txt
in the current directory.
If the file already exists, touch updates the access and modification timestamps of the file to the current date and time. This can be useful for updating the timestamp of a file to indicate that it has been modified, even if the contents of the file have not changed.
The -a
option can be used to change only the access timestamp and the -m
option can be used to change only the modification timestamp
touch
also accepts multiple files at a time, the command touch file1 file2 file3
will create new, empty files for file1
, file2
and file3
if they do not exist and update
their timestamps if they already exist.
touch
is commonly used in shell scripts to create or update files as part of an automated process. For example, a script might use touch
to create a new file as a marker that a
specific task has been completed, or to update the timestamp of a file to indicate that it has been processed.