cTime vs mTime vs aTime
This is once again very commonly asked question in most of the interviews. Usually it start with different question like “What is a inode structure or what information is available in a inode?” and then it gets pulled to the questions that “What is the different between cTime, mTime and aTime”. Though it is pretty straight forward but sometime it gets confusing.
mTime – File Modify Time:
As name suggests, it is file modification time. Whenever you update the contents of file, like add few lines or delete few, this time stamp is updated in the inode.
Some of following operations could lead to update of this:
echo “hi” > abc.txt
vim > abc.txt
cTime – inode/File Change Time:
There have always been a great confusion in cTime. Sometime people say it as “File Creation Time”, which is obviously not true at all. Actually it is File/inode change time. Now, the bigger confusion, that what is the difference between cTime and mTime then. So, mTime gets updated when you update the file, but cTime gets updated when you update the file attributes, like changing the permissions of file, moving the file to some other filesystem, changing the owner. That’s why it is also said “inode change time”, as in reality the file is not updated but just the inode information is updated.
So, mostly you will find cTime and mTime as same, as whenever you update the contents of the file, it will update the file mTime and cTime, unless you just update the file attributes only.
aTime – File Access Time:
This is the time when the file is last accessed. This doesn’t simply count when you opened the file for editing, but also count when you simply used the file for any operations like cat, grep, sort etc. So, even when you used the command “head” to read first 10 lines of file, the inode is updated with that time stamp.
Hope this will help you at some point.
More questions/tips coming soon, stay tuned.