Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I have a list of several thousand gzip (*.gz) files that I'd like to zgrep through, but I only want to run it on files with a last-modified-timestamp on or after yesterday (11/22/2012) and that contain the string "widget" in their filnames (filtering by these reduces the number of files to about 80).

I don't see any timestamp or file pattern arguments that I can add to my zgrep command - any ideas?

For example:

eijdij8484.gz modified last on 11/20/2012 <== dont zgrep
dj8j4848ju-widget-dj8d4dj48d.gz modified last on 11/20/2012 <== dont zgrep bc of timestamp
ijdijdijdjii.gz modified last on 11/23/2012 <== dont zgrep bc no "widget" in filename
3ijdidj4-widget-jd9idj48.gz modified last on 11/22/2012 <== zgrep!

Thanks in advance!

share|improve this question
up vote 1 down vote accepted

Something like this might get you going the right direction.

    for i in `find . -type f -name "*widget*.gz"; do
        modDate="`stat -c %y $i | awk '{print $1}' | sed 's/-//g'`"
        if [ ${modDate} < ${cutoff} ]; then
            command here on $i

This was a quick write-up because my wife is waiting on me to get out of the house, so try that for a bit and I will try to test it out more in-depth later this evening.

Edit - Is this meant to be a floating "yesterday" relative to the current day? Or is it a hard "11/22/12"?

share|improve this answer
Floating yesterday, but dont sweat it - i can tweak it from here, thanks!! – pnongrata Nov 24 '12 at 0:13
Awesome, hope it gets you where you want to be! – nerdwaller Nov 24 '12 at 1:53
If you want it: date --date='1 day ago' +%Y%m%d does it. – nerdwaller Nov 24 '12 at 2:18

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.