Bash: Find Files that Have Been Changed in Last 24 Hours


Often you may want to use Bash to find all files that have been changed in the last 24 hours.

You can use the following syntax to do so:

find . -mtime -1

This particular syntax will return all files in the current directory that have been changed in the last 24 hours.

Note that we use the command -mtime -1 to match all files that have a modification time less than one day, i.e. 24 hours from the current time.

It’s worth noting that the n command uses the following logic:

  • -mtime +n: Match files modified more than n days ago
  • -mtime n: Match files modified exactly n days ago
  • -mtime -n: Match files modified less than n days ago

Note that you can also replace find . with find /some/directory/path to match all files in a specific directory that have been changed in the last 24 hours.

The following example shows how to use this syntax in practice.

Example: Find Files that Have Been Changed in Last 24 Hours in Bash

This article is currently being written on 7/29/2024 around 11 AM.

Suppose we use the ls -l command to first view all files in our current directory along with their most recently modified time:

Now suppose that we would like to find only the files in the current directory that have been changed in the last 24 hours.

We can use the following syntax to do so:

find . -mtime -1

The following screenshot shows how to use this syntax in practice:

Bash find files that have changed in last 24 hours

Notice that this returns the following two files from the current directory:

  • teams1.txt
  • teams2.txt

We can view the output from the previous ls -l command to confirm that these two files have indeed been changed within the last 24 hours.

Related Tutorials

The following tutorials explain how to perform other common tasks in Bash:

Bash: How to List All Files in Folder by Size
Bash: How to List All Files in Folder Without Extension
Bash: How to List All Files Matching a Specific Pattern

Leave a Reply