How-To Geek
Get Last Accessed File Time In Ubuntu Linux
Ubuntu Linux has a rich set of commands for manipulating and accessing files. The stat utility gives detailed access to file information, including last accessed and last modified file time.
From the terminal window, run the command with this syntax:
stat filename
Here’s an example of checking the last time I’ve run Firefox on one of my machines:
[geek@ubuntu firefox]# stat firefox-bin File: `firefox-bin' Size: 9781136 Blocks: 19136 IO Block: 4096 Regular File Device: 302h/770d Inode: 555615 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 500/ geek) Gid: ( 500/ geek) Access: 2006-01-14 17:41:15.000000000 -0500 Modify: 2005-05-11 14:17:00.000000000 -0400 Change: 2005-05-13 23:31:44.000000000 -0400
I guess I haven’t used that box in a while… last time I used firefox was january 14th.
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (3)
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 11/26/06




Is there any way to know who accessed the file last time.
Kash,
Most likely, no. You can see the structure describing file status in POSIX by executing the following command “man 2 stat”.
That structure is
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
There is no field related to who accessed the file.
The information available might depend on your filesystem type. I’m guessing an old FAT12 floppy won’t have as much metadata about the files as something on ext4. Also many SSD users mount their filesystems with the option “noatime” which might make the access time property incorrect, even when read with stat.