Digital Media Insights for Business Owners

Search / Find files modified in the last x days with Bash in Terminal

So, if you are like me, sometimes for any number of reasons, you have to find all the files of a certain type that have been modified lately. For example, if a client had a security problem with their website and you would like to check what files where modified since the last backup. Or let’s say that you don’t remember what files you modified the last time that you made some changes to a directory, etc.

Here it is:

find directory_name/ -mtime -days_number -ls | grep "php"

Find is the command name that we are going to use.

directory_name is the name of the directory that you want to search. For example, you would search in www/ or in public_html/

-mtime is the flag that states modified time.

-days_number is a number, either positive or negative , for the files in days. So for example: -10 (means modified in the last 10 days).

-ls means list them.

| the pipe symbol passes the output of the first declaration to the input of the second declaration.

grep is used to match. In this case, in the results, find the files that have a “php” or a “jpg” or anything that you want.

And that is it! You don’t need anything else. Hope that helps –


Say: "Hola" to your new clients.

Follow us on Social Media for more Tips & Tricks.

Other Posts You May Enjoy