The -mtime option can be used to return files and directories that were modified x or more days ago. For example, to return files and directories that were modified 14 or more days ago below the tmp directory.
find /tmp -mtime +14
Or to return files and directories that were modified in the last x days. For example, to return files and directories that were modified in the last 14 days below the tmp directory.
find /tmp -mtime -14
For example, to return files and directories that were not modified 14 or more days ago below the tmp directory.
find /tmp ! -mtime +14
- The -atime option can be used to return files and directories that were accessed 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 modified in the output.
- %y = time last modified
- %n = file name
find /tmp -exec stat --format "%y %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