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?

Corey S.
  • 2,487
  • 1
  • 19
  • 23

4 Answers4

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
Heath
  • 1,260
  • 9
  • 4
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.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
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

Roy
  • 4,376
  • 4
  • 36
  • 53
  • 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 07 '09 at 15:09
0

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

ls -al LOGDIRECTORY | grep 'YOUR DATE'
jomey
  • 312
  • 1
  • 3