Search notes:

Shell command: touch

touch can be used to change a file's atime and mtime (but not to change its ctime).
If the «touched» file does not exist, it will be created (except when -c is specified)

Options

-a Change only access time
-c, --no-create Don't create any files
-d, --date =STRING Parse STRING and use it instead of current time
-f ignored
-h, --no-dereference Affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink)
-m change only the modification time
-r, --reference =FILE use file's times instead of current time
-t STAMP Use [[CC]YY]MMDDhhmm[.ss] instead of current time
--time =WORD Change the specified time: WORD is access, atime, or use: equivalent to -a. WORD is modify or mtime: equivalent to -m`
--help
--version

-t specify a timestamp

-t can be used to specify a timestamp in [yy]yymmddhhmm[.ss] format.
In the following example, -t is combined with -a to change the access and -m to change the modification time.
stat with the %x and %y format is then used to verify if these dates were changed.
touch -m -t 201011121314.15 touched
touch -a -t 201211100908.07 touched

stat --format="Last access time:       %x"  touched
stat --format="Last modification time: %y"  touched
Github repository shell-commands, path: /touch/t_specify-timestamp

-d

-d can be used to specify an arbitrary (possibly relative) date with which the file is created or touched.
touch -d "10 days ago" ...
See also: https://github.com/ReneNyffenegger/shell-commands/blob/master/touch/d_10-days-ago
Compare with the -d flag of date.

-r

Use another file's timestamp.
touch -r another-file file-to-touch ...
sa https://github.com/ReneNyffenegger/shell-commands/tree/master/touch/r_another_file

See also

Other shell commands such as truncate
Simulating touch in PowerShell with
The Perl module File::Touch

Windows

In PowerShell, an empty file can be created with set-content empty.txt $null. This command creates a zero byte file named empty.txt.
A file's timestamp can be updated with (get-item path\to\file.txt).LastWriteTime = (get-date).
touch.ps1 is a PowerShell Scripts that creates a file if it does not exist or updates an existing file's timestamps.
fsutil.exe file createNew, which in cmd.exe or PowerShell can be used to create empty files.

Index