touch
Explanation
The touch command is primarily used to update the access and modification times of a file to the current time. If the file does not exist, touch creates an empty file, which is its most common use case for beginners.
Basic Syntax
touch [OPTION]... FILE...
Common Flags and Options
| Flag | Description |
|---|---|
-a | Change only the access time. |
-m | Change only the modification time. |
-c, --no-create | Do not create any files if they don't exist. |
-d, --date=STRING | Parse string and use it instead of current time. |
-r, --reference=FILE | Use this file's times instead of current time. |
Real-world Examples
-
Create an empty file:
touch newfile.txt -
Create multiple empty files:
touch file1.txt file2.txt file3.txt -
Update timestamps of an existing file:
touch existingfile.txt