How to Display When a File was Last Accessed in Ubuntu

As a Ubuntu user, you would agree how powerful and rich is the set of commands that you can use to access and manipulate files. In this tutorial, we will explore one such command, the Linux stat command. This command, when used with a file name, gives the following useful information about the file:

  • Size
  • Type
  • IO Block
  • Device
  • Inode
  • User ID
  • Group ID
  • Access Time
  • Modification Time
  • Creation Time

In this article, we will explain how you can use the stat command to view when a specific file was last accessed.

We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system. We will be using the Ubuntu command line, the Terminal, to see the stats of a file. You can open the Terminal application either through the system Dash or the Ctrl+Alt+T shortcut.

This is the simple syntax of the stat command that you can use to view the last access time of a file:

$ stat filename

For example, this is the output of the stat command I ran on one of my files:

View file access date with stat command on Ubuntu

The “Access” details in the output indicate the exact information that we are looking for.

You can also view when an application was last accessed by printing the statistics of the file that launches that application. For example, if you want to view when Firefox was last launched, move to the /usr/bin folder and then use the following command to view last accessed time of Firefox:

$ stat firefox

Linux stat command example

The stat command is much more powerful than this. To view it's full capacity you can view the manpage through the command, ‘man stat’.