Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to find all php files within a certain directory that have been modified on a certain date

I'm using

find /var/www/html/dir/ -mtime -28 | grep '\.php' 

to get files modified within the last 28 days, but I only need files that have been modified on the following date: 2011-02-08

share|improve this question
up vote 9 down vote accepted

On recent versions of find (e.g. GNU 4.4.0) you can use the -newermt option. For example, to find all files that have been modified on the 2011-02-08

$ find /var/www/html/dir/ -type f -name "*.php" -newermt 2011-02-08 ! -newermt 2011-02-09

Also note that you don't need to pipe into grep to find php files because find can do that for you in the -name option.

Take a look at this SO answer for more suggestions: How to use 'find' to search for files created on a specific date?

share|improve this answer

Annoyingly, there isn't any direct way with standard find. Recent versions of find on GNU systems (e.g. non-embedded Linux, Cygwin) and some *BSDs have options such as -newermt to compare a file date with a spelled-out date.

With standard find, all you can do is compare the file date with the current date (-mtime) or with a fixed file. The current date is usually not useful in this case (it counts back from the time you run the find command, whereas most applications require a calendar date). That leaves you with the kludge of creating temporary files to define a range.

touch -t 201103070000 start.tmp
touch -t 201103080000 stop.tmp
find . -newer start.tmp \! -newer stop.tmp -print
rm start.tmp stop.tmp
share|improve this answer

You have almost the right command already, for versions of find that won't let you use dates:

find /var/www/html/dir/ -mtime 27 | grep '\.php'

In general, for find -n means fewer than, n means equal, +n means "more than". Traditional find has some exceptions, but GNU find and other newer versions such as on BSD/Mac OS X corrected those. (Keep this in mind if you ever find yourself on a Solaris or other commercial Unix system.)

share|improve this answer

With zsh you could use the function age to print only the names of files that have been modified on a certain date:

autoload age
print -rl -- *.php(.e:age 2011/02/08:)

or, if you want to search recursively:

autoload age
setopt extendedglob
print -rl -- **/*.php(.e:age 2011/02/08:)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.