The touch
utility on macOS has a -A
option that allows you to adjust the modification and access timestamps on set of files ("mtime" and "atime" respectively) by a number of hours, minutes and/or seconds. In comments, you appear to want to set the timestamps to the current time, not adjust them. The -A
option would therefore be the wrong option to use.
To change the mtime and atime timestamps on a set of files to the current time, use
touch -c pattern
where pattern
is some pattern that matches the files you'd like to touch. The -c
option makes sure that you don't create files if the pattern does not match, or if you provide an explicit list of files that contains nonexistent names.
As a side effect of modifying the mtime and atime timestamps, the ctime timestamp ("inode change timestamp") will also be modified.
To set the btime ("birth timestamp", which may be what you call the "creation timestamp" in your comment), you may want to use the (deprecated) SetFile
command, which is used to "set attributes of files and directories" on macOS.
SetFile -d "$(date +'%m/%d/%Y %H:%M:%S')" pattern
Use SetFile
with the same datestamp string with the -m
option to update the mtime. Setting the btime or mtime in this manner also updates the ctime of the file. The SetFile
utility does not/can not update the atime timestamp.
touch
has-A
(adjust). OP, could you elaborate on "immediate date" ? Does that mean current time/date ?-A
seems like a complicated way to do it.now
.touch
, only mtime &/or atime. The ctime can be modified, but it's not easy to set it to a time of your choice. See this Stack Exchange question java.nio.Files - setting “Change time” attribute on a file for some info.