How does `stat` show file timestamps?

QuestionsQuestions8 SkillsProDec, 21 2025
0189

That's a great question! While ls -l only shows you the Modify time, the stat command provides a much deeper look into a file's history.

When you run stat file1.txt, look at the bottom section of the output. Linux tracks three distinct timestamps:

1. Access (atime)

  • Definition: The last time the file's content was read.
  • Trigger: Using commands like cat, less, grep, or when a program opens the file to read it.
  • Note: On many modern Linux systems, this isn't updated every single time to improve performance, but it gives you a general idea of usage.

2. Modify (mtime)

  • Definition: The last time the file's contents were changed.
  • Trigger: When you edit a file (e.g., adding text with echo "hello" > file.txt or saving it in vim).
  • This is the date you normally see when you run ls -l.

3. Change (ctime)

  • Definition: The last time the file's metadata or status was changed.
  • Trigger: Whenever the mtime changes, OR when you change things like permissions (chmod), ownership (chown), or the filename.

4. Birth (often shown as - or empty)

  • Definition: The original creation date of the file.
  • Note: Not all Linux filesystems support this, so you will often see it as blank or -.

Try it yourself!

Run these commands to see the timestamps change in real-time:

  1. Check current stats:
    stat file2.txt
  2. Access the file (Update Access time):
    cat file2.txt
    stat file2.txt
  3. Change permissions (Update Change time):
    chmod 666 file2.txt
    stat file2.txt

You will notice the "Change" timestamp updates even though the content of the file stayed the same!

Does that help clarify the difference between the various timestamps?

0 Comments

no data
Be the first to share your comment!