3

I'm sure this is an age old question with a simple answer, but I've tried every combination I know to try and haven't come up with anything. And searching Google is less than pleasant since searching this topic comes up with hundreds of way to "find yesterday's date using the date command".

Anyway, I am trying to use find to select a list of files that were modified yesterday. The goal is to select yesterday's log files out of a directory to do something specific with them. The directory contains multiple days of log output.

The best I can get is find returning yesterday's files WITH today's files listed as well. I do not want to see today's files -- just yesterday.

I will also throw in the gotcha: this is AIX find, NOT the GNU find you'd find in most Linux distros. So -daystart is not an option available to me. (Thought of that one already!)

Anyone know an effective way to list out yesterday's files using find on AIX?

| improve this question | | | | |
5

One possibility: build GNU 'find' on your box and use that instead of the stock 'find'.

Or, if AIX find has the -newer test, you could do something like this:

# midnight oct 7
touch -t 10070000 today.ref
# midnight oct 6
touch -t 10060000 yesterday.ref

find /dir -newer yesterday.ref -a \! -newer today.ref -print
rm today.ref yesterday.ref
| improve this answer | | | | |
1

You can deduct the number of minutes of the current time since midnight and use -mmin:

min=$(date +%M); currtime=$(($(date +%k)*60 + ${min#0*} )); find /some/dir -mmin -$((currtime + (24 * 60))) -a -mmin +$((${currtime} + 1))

You might need to make some adjustments to the offsets. I don't have many files at the right times to do a lot of edge-case testing.

| improve this answer | | | | |
0

Depending on what you need to do with them, how about a simple ls + grep solution?

ls -al LOGDIRECTORY | grep 'YOUR DATE'
| improve this answer | | | | |
0

Won't find . -mtime 1 do the trick?

If you need it to be yesterday and can't run it close to midnight, I suppose you could work someting out with using two -mmin options to specify a bracket of time.

So if it's 01:00 you could do find . -mmin +60 -mmin -1500

| improve this answer | | | | |
  • No, that specifies 1 24 hour period (starting now), not a 24 hour period starting at 00:00:00 hours yesterday, which is what the poster wants. – Scott Pack Oct 7 '09 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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