When was a file last opened?
12,323
Solution 1
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! :)
Solution 2
Try:
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
Solution 3
You need to use GNU stat
command. Example: stat my_file.txt
will give you what you are looking for.
Related videos on Youtube
![tlehman](https://i.stack.imgur.com/H7vPm.jpg?s=256&g=1)
Author by
tlehman
Currently building Harvester HCI at SUSE. Former AWS
Updated on September 18, 2022Comments
-
tlehman almost 2 years
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.-
goldilocks almost 10 yearsIn 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. -
Stéphane Chazelas almost 10 years@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
).
-
-
tlehman almost 10 yearsI 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. -
cuonglm almost 10 years@TobiLehman: See updated answer.
-
Timothy Martin almost 10 years@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
-
Stéphane Chazelas almost 10 yearsWith GNU
ls
, use--full-time
to get the full time (with as much precision as available). -
Stéphane Chazelas almost 10 years
linux
has notstat
command, Linux is just a kernel. There are severalstat
commands found on Linux and non-Linux based systems like GNU stat, zsh stat... -
Stéphane Chazelas over 7 years(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)