Finding files on modified on a specific day

We can use “find . -mtime +/-n” command to locate all files which have been modified  befer/after 24*n hours counting from the time when you launch “find”.  However, it can finish to a middle of a day. if we wish to find files modified on a particular day, E.g. if we run a command at 10 am on 15 Feb.2010 as


find . -mtime +1

in hoping to find all files modified before Feb.14 of 2010. It will not fulfill our requirement. It not only returns files modified before Feb.14 of 2010 but also files modified between 0 and 9.59am on Feb.14 of 2010, which is not what we expected.

Some version of “find” includes an option -daystart to adjust counting time to the beginning of a day as:


find . -mtime +1 -daystart

However this option is not generally available.

We can overcome the limit by merging usage of touch command


touch -t '201002140000' /tmp/start_of_20100214
touch -t '201002140000' /tmp/end_of_20100214
find . -newer /tmp/start_of_20100214 ! -newer /tmp/end_of_20100214 -print

Here is an example using the method: Archiving log files on a date range

Advertisements
Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: