How to alter only access time, modify time or change time of files or folders in Linux


Read this article to know how to change only the atime, ctime or mtime of a file or directory in Linux in the most simplest of the way.

Access time (atime), Modify time (mtime) and Change time (ctime) are metadata of files and folders in a Linux distributions. These can be checked by using stat command on a file or folder:
stat file1 or stat dir1

Before I tell you how to modify any of these values let me explain in brief what exactly are these.

  1. Access time: Access time is the time when the file was last read. This can be by way of a text editor, cat, head, tail, grep etc commands. So whenever you use any of such commands on a file, its atime will be updated.

  2. Modify time: Modify time is the time when you last updated a file by way of modifying the content. This would update the mtime.

  3. Change time: Change time is when you update the file attributes of a file. This is inode change time, so whenever you update attributes like permission, user or group, the ctime also change. However, do keep in mind that any action that changes the mtime also change the ctime.

Now let's see how we can update each one of the individually:

Updating atime, mtime or ctime of a file


Updating these for a file is quite easy. If you see the man page of touch command you will see that it has parameters which are specifically there to update only ctime or the mtime.

To update only atime of a file - touch -a file1
To update only mtime of a file - touch -m file1
To update only ctime of a file - chmod 777 file1 [Note: Use just need to change the permissions, the combination can be anything like 544, 111 and so on..]

Updating atime, mtime or ctime of a directory


Please note that it is not possible to modify the mtime without modifying the ctime.

To update only atime of a directory - Use cat command on a file inside the directory you want to change the atime for.
To update only ctime of a directory - chmod 777 dir0
To update mtime of a directory - Touch a file or create a subdirectory inside the directory you want to change mtime for.

Read How Fedora Linux is better than Windows OS?


Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email:
    -