Linux find command - find files modified recently
I don't write about Unix and Linux very much on this website, but when I just used a Linux find command to find files that had been modified in the last seven days, a friend said I should write a quick blog post about it.
Finding a file that has been modified in X days
Here's a simple Linux find command that shows how to find a file or directory that has been modified in the last seven days:
find . -mtime -7
This find command searches within the current directory (designated by the first ".") for all files and directories that have been modified in the last seven days.
As slight variations of that command, here's how you search for just files that have been modified in the last seven days:
find . -mtime -7 -type -f
and here's how you search for just directories that have been modified in the last seven days:
find . -mtime -7 -type -d
As one final variation of this find command, let's assume you want to search the "/tmp" directory instead of the current directory for files modified in the last three days:
find /tmp -mtime -3 -type -d
Linux find command with mtime - Summary
I hope these find command examples showing how to use the 'mtime' option have been helpful. As you can see from all of the examples I've shared, the find command is a powerful command for searching for and finding files and directories, with an incredible number of options.
Recent blog posts
- Free Scala and functional programming video training courses
- Free: Introduction To Functional Programming video training course
- The #1 functional programming (and computer programming) book
- The User Story Mapping Workshop process
- Alvin Alexander, Certified Scrum Product Owner (CSPO)
- Alvin Alexander is now a Certified ScrumMaster (CSM)
- Our “Back To Then” app (for iOS and Android)
- A Docker cheat sheet
- Pushing a Scala 3 JAR/Docker file to Google Cloud Run
- Reading a CSV File Into a Spark RDD (Scala Cookbook recipe)