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?


Related Articles

User ID and User types in UNIX Operating Systems

This article explains about, what exactly is an USER ID in UNIX operating system and how is that been represented and stored in "passwd" file with the user details. Also, read this article to know about the range of user ids and their special permissions.

How to disable Bluetooth in Fedora 19 at start up?

Does your Fedora 19 automatically starts Bluetooth in GNOME 3 shell? Are you messed up and want to disable Bluetooth at start up in Fedora 19? Read the below article and disable Bluetooth service at start up in Fedora 19.

How to watch Netflix in Fedora

Need to watch Netflix movies and TV shows in Fedora? Below I have given tutorial to install and watch Netflix movies in your computer running Fedora operating system. Read the below article to install Netflix in Fedora.

How to backup files in Fedora OS using Deja-Dup in simple steps?

Are you wondering how to back up your files in Fedora OS? Are you looking for easy way to back up files? Here is the tutorial which helps you to back up file with several handy options for you. Here I have given screen by screen procedure to install back up software and using it.

More articles: Linux tutorials

Comments

No responses found. Be the first to comment...


  • 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: