Linux find search for files changed in date range

Introduction

In this quick guide, we’ll explore some useful bash commands to find files modified within a specific time frame. This is especially useful for system administrators and developers.

Finding Files Modified Today

To find all files in a directory that were modified today, you can use the following command:

find /dir -type f -mtime -1

This command searches for files (`-type f`) in the `/dir` directory that have been modified in the last 1 day (`-mtime -1`).

Finding Files Modified Exactly N Days Ago

If you need to find files changed exactly N days ago, use:

find /dir2 -type f -mtime n

Replace `n` with the number of days ago you are interested in.

Deleting Files Modified More Than M Days Ago

To find and delete files modified more than M days ago, proceed with caution and use:

find /dir3 -type f -mtime +m -exec rm -fv {} \;

Warning: This command will delete files. Use it carefully.

Conclusion

These are just a few basic but powerful ways you can manage your file system more effectively using bash commands.