linux modify file access time modification time

If no time is specified, it defaults to 00:00:00

touch -d "2010-05-31" a.txt

touch -d "2010-05-31 08:10:30" a.txt

 

Only modify modification time

touch -m -d "2010-05-31" a.txt

 

Only modify access time

touch -a -d "2010-05-31" a.txt

 

The time format can be written without double quotation marks. Personally, it is better to write it.

 

touch --help
Usage: touch [options]...files...
change the access time and modification time of each file to the current time.

Files that do not exist will be created as empty files unless the -c or -h option is used.

Special treatment if the filename is "-", changing the access time of the file relative to standard output.

Parameters that are required for long options are also required for short options.
  -a change access time only
  -c, --no-create do not create any files
  -d, --date=string use specified string for time instead of current time
  -f (ignore)
  -h, --no-dereference Affects the symlink itself, not the destination indicated by the
    symlink (this option is only useful when the system supports changing the owner of a symlink)
  -m only change the modification time
  -r, --reference=file uses the specified file's Time attribute instead of the current time
  -t STAMP Use the time in [[CC]YY]MMDDhhmm[.ss] format instead of the current time
  --time=WORD Use the time specified by WORD: access, atime, use are all equal to
   the -a option effect, and modify, mtime is equal to the effect of the -m option
      --help display this help information and exit
      --version display version information and exit

Note that the -d and -t options accept different time/date formats.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326539130&siteId=291194637