Change File Date in Linux With Touch

Last updated on Dec 28, 2019 in Linux

Linux has three different timestamps in a file: last access time, last modification time and last change time. They are briefly described below:

  • last access time (atime): file is accessed (opened) but not changed
  • last modification time (mtime): file’s content is changed
  • last change time (ctime): file’s content, permissions or name is changed

In following examples, we want to set the file myfile.txt to 15th of June 2019 and 10:15 AM.

Edit Last modification Time

$ touch -m -t 201906151015 myfile.txt

Where the t stands for time which we set explicitly. The format is YYYYMMDDHHmm. The -m means that we only want to change the modification time (as the content would be changed in that time).

Edit Last Access Time

$ touch -a -t 201906151015 myfile.txt

The -a means that we only want to change the access time (as the file wouldd be opened in that time, but not changed).

Edit Last Change Time

The last change time cannot be edited with touch command.