How do I determine, when a file was last opened?

I've looked at man ls (using GNU coreutils 8.22) and I don't see anything about this timestamp.

  • 3
    In general it's called "access time" or atime. Note that it can be disabled for ext filesystems, meaning it will not be updated for files as long as the fs is so mounted. – goldilocks Jul 2 '14 at 18:02
  • 1
    @goldilocks, access time is the time the file was last read, not open. Opening a file (as in the open() system call) doesn't update any time stamp unless it's an open with truncation (O_TRUNC). – Stéphane Chazelas Jul 2 '14 at 18:40

You may want to check this:

ls -l --time=atime

atime — updated when file is read
mtime — updated when the file changes.
ctime — updated when the file or owner or permissions changes.

Have fun! :)

  • (note that none of them is for the time the file was last open which is not an information that is recorded. Also, for performance reason, atime is rarely always updated nowadays) – Stéphane Chazelas Mar 14 '17 at 6:24


ls -lu

If you want sorted result by access time:

ls -ltu

From man ls:

-u     with  -lt:  sort  by, and show, access time with -l: show access
              time and sort by name otherwise: sort by access time

If you want to get full date time, use --full-time:

$ ls -ltu --full-time

Or use GNU stat:

$ stat -c "%x" -- test.txt 
2014-06-30 19:21:05.481161360 +0700
  • I am only getting month and day of access time, is there a way to get the year? I tried using date like args, but that didn't work. – tlehman Jul 2 '14 at 17:49
  • @TobiLehman: See updated answer. – cuonglm Jul 2 '14 at 17:54
  • @TobiLehman According to real-world-systems.com/docs/ls-info.html: "However, the default POSIX locale uses a date like Mar 30 2002 for non-recent timestamps, and a date-without-year and time like Mar 30 23:45 for recent timestamps. A timestamp is considered to be "recent" if it is less than six months old, and is not dated in the future. If a timestamp dated today is not listed in recent form, the timestamp is in the future, which means you probably have clock skew problems which may break programs like make that rely on file timestamps." --Emphasis mine – Timothy Martin Jul 2 '14 at 18:02
  • With GNU ls, use --full-time to get the full time (with as much precision as available). – Stéphane Chazelas Jul 2 '14 at 18:41

You need to use GNU stat command. Example: stat my_file.txt will give you what you are looking for.

  • 1
    linux has not stat command, Linux is just a kernel. There are several stat commands found on Linux and non-Linux based systems like GNU stat, zsh stat... – Stéphane Chazelas Jul 2 '14 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.