Find When a File Was Accessed on Linux
In this article
To find when a file was accessed on Linux, use the stat command followed by the file path; it displays the access time in the Access: line. For example, stat file.txt shows the last access timestamp. You can also use ls -lu for a quick list view or find with -atime to locate files accessed within a specific time range.
Understanding Access Time (atime)
Linux stores three timestamps for every file: modification time (mtime), change time (ctime), and access time (atime). The access time records the last time the file's content was read—for example, when you open it with cat, edit it in a text editor, or use it as input to a command. It does not update when you list the directory or change file permissions; those actions affect ctime instead.
Historically, atime was updated on every read, which caused significant disk I/O on busy systems. To mitigate this, modern Linux distributions often mount filesystems with the relatime option, which updates atime only if the previous atime is older than mtime or ctime, or if it is more than 24 hours old. This means atime may not reflect every single read, but it gives a close approximation of the last meaningful access.
Using stat to View Access Time
The stat command is the most direct way to see the access time. Run it from the terminal:
stat filename
The output includes a line like:
Access: 2025-03-14 09:30:45.123456789 +0000
If you want only the access time, use the -c format specifier:
stat -c '%x' filename
This prints just the access timestamp in a default format. You can customize it with %X for seconds since epoch or %w for birth time (if supported).
Using ls to List Access Times
The ls command normally shows modification time by default. To display access time, use the -u flag:
ls -lu filename
For a directory listing sorted by access time (oldest first), combine with -t:
ls -lut /path/to/dir
To see all three timestamps in a detailed listing, use ls -l --time=atime (GNU coreutils) or simply rely on stat.
Finding Files by Access Time with find
If you need to locate files accessed within a certain number of days, the find command is your tool. Use the -atime option with a number of days:
find /path -atime -7
This finds files accessed less than 7 days ago. A plus sign (+7) means more than 7 days, and an exact number (7) means exactly 7 days (rounded down). For minutes, use -amin:
find /path -amin -30
This shows files accessed within the last 30 minutes. Combine with -type f to restrict to regular files, or -name to filter by pattern.
Common Pitfalls and Misconceptions
A frequent misconception is that atime updates every time you view a file in a file manager or run ls. In reality, merely listing a directory does not update the atime of the files inside it—only reading the file's content does. Additionally, on filesystems mounted with noatime, atime is never updated at all, so the timestamp reflects the last access before that mount option was set. You can check your mount options with mount | grep ' / ' or findmnt /.
Another pitfall: if you copy a file with cp, the new file's atime is set to the current time (or the source's atime if you use cp -p). This means the access time of the copy may not match the original. For forensic or audit purposes, always verify the filesystem mount options and whether the file was copied or moved.
Alternatives: atime in File Managers and GUI Tools
Most graphical file managers (like GNOME Files or Dolphin) show modification time by default, but you can often enable an access time column in the view settings. For example, in GNOME Files, go to Preferences → List Columns and check “Accessed”. In Dolphin, right-click the column header and select “Access Time”. These tools read the same underlying stat data, so they show the same value as the command line.
For system-wide monitoring, you can use lsof to see which processes currently have a file open, but that does not give historical access times. The auditd subsystem can log access events in real time, but it requires configuration and is overkill for simple queries.
When Access Time Matters
Access time is useful for cleanup scripts that delete old files, for detecting if a file has been read recently (e.g., in security investigations), and for backup tools that need to know which files have been read since the last backup. However, due to relatime and noatime, you should not rely on atime as a precise audit trail. For legal or forensic evidence, you would typically use filesystem journaling or dedicated tools like debugfs on ext4, which can access raw inode data.
If you need to preserve the original atime when copying files, use cp -p or rsync -t (which preserves times). For moving files within the same filesystem, mv preserves all timestamps.
Frequently Asked Questions
Does atime update when I open a file in a text editor?
Yes, opening a file for reading (even if you don't modify it) updates atime, provided the filesystem is not mounted with noatime. However, with relatime, the update may be suppressed if the atime is already newer than mtime or ctime and less than 24 hours old.
Why does atime show an old date even though I just read the file?
This usually happens because the filesystem is mounted with noatime or relatime and the conditions for an update are not met. Check your mount options. Also, some applications read files without updating atime (e.g., using O_NOATIME flag), though this is rare.
Can I change the access time of a file?
Yes, you can use the touch command with the -a option to set the access time manually. For example, touch -a -d '2024-01-01 12:00' file sets atime to that date. This requires write permission on the file.
What is the difference between atime, mtime, and ctime?
Atime (access) is when the file content was last read. Mtime (modify) is when the file content was last changed. Ctime (change) is when the file's metadata (permissions, owner, link count) was last changed, and it also updates when mtime changes. Ctime cannot be set manually.
How do I see access time for all files in a directory?
Use ls -lu /path/to/dir to list files with their access times. For a more detailed output with all timestamps, use stat on each file or find /path -type f -exec stat -c '%x %n' {} \;.
Does accessing a file over SSH or NFS update atime?
Yes, if the server's filesystem is mounted with default options (or relatime), reading a file over SSH or NFS will update atime on the server. However, some network filesystems (like NFS with noatime) may disable it. Check the server's mount options.