Linux Question: grep through recent files

Discussion in 'OT Technology' started by pepdog, Dec 27, 2007.

  1. pepdog

    pepdog New Member

    Joined:
    Nov 21, 2005
    Messages:
    4,211
    Likes Received:
    0
    Location:
    seattle
    Hi, i'm on Linux and have a grep question. I want to find all files that have a certain string, but only in files from the last 2 days. i'm pretty sure i've used it before, just can't remember it.

    anyone know the command? :bowdown:
     
  2. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,458
    Likes Received:
    12
    I don't know if you can do that with just grep.

    find . -mtime -2 -type f -exec grep STRING {} \;

    -exec is slow to better to pipe it into xargs and run:

    find . -mtime -2 -type f | xargs -i grep STRING {}

    That's the gist of it.

    Cd into the directory that you want to grep or enter in the full path for find. Use modified time or create time. Tell it how many directory levels to traverse. Tell it to stay on the file system... etc. Lots of options for find.
     

Share This Page