How to Find Files Modified Exactly N Days Ago (find -mtime)

The Historical Data Search

In Ubuntu Linux, managing log rotation and performing forensic investigations often requires searching files based on days rather than minutes. If a server experienced a critical crash exactly a week ago, searching for files modified “sometime in the last 7 days” will return too much noise. You need the ability to instruct the filesystem to return only files that were modified inside a highly specific, 24-hour historical window.

Using the find Command with -mtime

The Linux find command utilizes the -mtime (modified time) flag to search the filesystem based on 24-hour day increments.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the /var/log/ directory for any files that were modified exactly 7 days ago, type the following command exactly:
  3. sudo find /var/log/ -type f -mtime 7
  4. Press Enter and provide your administrator password.

The 24-Hour Math

The syntax utilizes a strict 24-hour block system. By providing the exact integer 7 without a plus or minus operator, the search engine calculates the time exactly 168 hours ago (7 x 24), and creates a 24-hour window from that point. It will only return files modified within that specific historical day. This allows administrators to surgically extract log files from the exact day a server anomaly occurred, without having to manually parse through thousands of newer or older files.

Get the best tech tips delivered straight to your inbox.

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