Bootstrap FreeKB - Linux Commands - find command - date accessed (-atime)
Linux Commands - find command - date accessed (-atime)

Updated:   |  Linux Commands articles

The -atime option can be used to return files and directories that were accessed x or more days ago. For example, to return files and directories that were accessed 14 or more days ago below the tmp directory.

find /tmp -atime +14

 

Or to return files and directories that were accessed in the last x days. For example, to return files and directories that were accessed in the last14 days below the tmp directory.

find /tmp -atime -14

 

To return files and directories that were not accessed 14 or more days ago below the tmp directory.

find /tmp ! -atime +14

 

NOTE - Listing a files attributes will not update the last accessed datetime of the file. You would need to do something like cat or touch to update the last accessed datetime of the file.

  • The -mtime option can be used to return files and directories that were modified x or more days ago.
  • The -ctime option can be used to return files and directories that were changed x or more days ago.

 

To include the date and time the file was last accessed in the output.

  • %x = time last accessed
  • %n = file name
find /tmp -exec stat --format  "%x %n" "{}" \;

 

This will return something like this.

2020-07-06 05:50:18.594805437 -0500 /tmp/foo.txt
2020-07-06 02:10:38.898884577 -0500 /tmp/bar.txt

 

The stat command can be used to display the time a file was last accessed (atime), last modified (mtime) and last changed (ctime).

~]# stat /tmp/foo.txt
  File: ‘/tmp/foo.txt’
  Size: 7940168         Blocks: 15520      IO Block: 4096   regular file
Device: fd04h/64772d    Inode: 105729      Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  409/ john.doe)   Gid: ( 2001/admins)
Context: system_u:object_r:usr_t:s0
Access: 2020-03-31 22:44:47.895474745 -0500
Modify: 2020-03-31 22:43:17.434452999 -0500
Change: 2020-03-31 22:43:17.434452999 -0500
 Birth: -

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 0656b6 in the box below so that we can be sure you are a human.