The touch
command is used to create empty files or update the access and modification timestamps of existing files. This command is useful for quickly creating new files or for updating the timestamps of files without changing their content.
Initial Example
Using touch
to create a new empty file called newfile.txt
:
touch newfile.txt
TOUCH Parameters
Parameter | Description |
---|---|
-a | Update only the access time of the file |
-c, --no-create | Do not create any files if they do not exist |
-d, --date=STRING | Use the specified date and time instead of the current time |
-f | Ignored; included for compatibility |
-h, --no-dereference | Affect the symbolic link itself, rather than the file it points to |
-m | Update only the modification time of the file |
-r, --reference=FILE | Use the times of the specified file instead of the current time |
-t [[CC]YY]MMDDhhmm[.ss] | Set the specified time using the given format |
--time=WORD | Specify which time to change: access time (-a ) or modification time (-m ) |
--help | Display help information and exit |
--version | Show version information and exit |
Examples
1. Create an Empty File
To create a single empty file:
touch filename.txt
2. Create Multiple Empty Files
To create multiple empty files at once, specify their names separated by spaces:
touch file1.txt file2.txt file3.txt
3. Update Timestamps of Existing Files
To update the access and modification timestamps of an existing file without changing its content:
touch existingfile.txt
4. Set a Specific Timestamp
To set a specific timestamp for a file, use the -t
option followed by the timestamp in the format [[CC]YY]MMDDhhmm[.ss]
:
touch -t 202404151230.00 file.txt
5. Change Only the Access Time
To change only the access time of a file, use the -a
option:
touch -a file.txt
6. Change Only the Modification Time
To change only the modification time of a file, use the -m
option:
touch -m file.txt