How to Find Files Accessed in the Last 7 Days in Ubuntu Linux

The Stale Data Audit

When managing storage on an Ubuntu Linux server, administrators frequently need to identify which files are actively being used and which files have been completely abandoned. If you have a massive directory of PDF reports, you cannot simply look at the creation date to determine if they are still relevant. Instead, you must instruct the Linux filesystem to filter the files based on when they were last read or opened by a user or an application, completely independent of when they were actually modified.

Using the find Command with -atime

The Linux find command utilizes the -atime (access time) flag to filter files strictly by the timestamp of their last read event.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the entire /var/www/reports/ directory for every single file that has been accessed or read within the last 7 days, type the following command exactly:
    sudo find /var/www/reports/ -type f -atime -7
  3. Press Enter and provide your administrator password.

Hunting Abandoned Files

The true power of the -atime flag is finding data you can safely archive. By swapping the negative sign for a positive sign, you invert the search. For example, running sudo find /var/www/reports/ -type f -atime +365 tells the server to find all files that have not been accessed in over 365 days. This instantly generates a highly accurate list of completely abandoned, stale files that are safe to move to long-term cold storage to free up immediate disk space.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.