Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
@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! :)

share|improve this answer


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
share|improve this answer
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.

share|improve this answer
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
@StéphaneChazelas edited, thanks! – Sunil Jul 3 '14 at 13:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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