LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-19-2014, 02:42 PM   #1
tabbygirl1990
Member
 
Registered: Jul 2013
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63

Rep: Reputation: 1
date option for grep ?


hey guys,

is there a date option for grep?

say i need to find all the files that were modified after a certain date.

i don't see that option, and I don't know of any "date" commands that i could pipe to grep.

ideas?

tabby
 
Old 08-19-2014, 02:45 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997
Quote:
Originally Posted by tabbygirl1990 View Post
hey guys,

is there a date option for grep?

say i need to find all the files that were modified after a certain date.

i don't see that option, and I don't know of any "date" commands that i could pipe to grep.

ideas?

tabby
You probably want to use find to select files by dates, then grep the results using find's exec, or pipe to xargs and grep.

See man find for it's extensive date options.

For example, to grep all files newer than some reference file:

Code:
find path -newer reffilename -exec grep 'somestring' \{\} \;
Or to grep in all files modified in the past 7 days:

Code:
find path -ctime -7 -exec grep 'somestring' \{\} \;
Sometimes the exec expressions can be confusing, so you can pipe the output of find to xargs/grep:

Code:
find path -ctime -7 |xargs grep -l 'somestring'
... which will give you just the file names modified in past 7 days with 'somestring' inside...

Last edited by astrogeek; 08-19-2014 at 03:28 PM. Reason: Added examples, typos, etc...
 
1 members found this post helpful.
Old 08-19-2014, 03:49 PM   #3
tabbygirl1990
Member
 
Registered: Jul 2013
Location: a warm beach, cool ocean breeze, nice waves, and a Margaritta
Distribution: RHEL 5.5 Tikanga
Posts: 63

Original Poster
Rep: Reputation: 1
thanks!
 
Old 08-19-2014, 04:08 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
Depending on which shell you use (most people use Bash) you may not even have to use the find command. For example, when using Zsh (my preferred shell) you can use its extended expansion features for that.
Code:
grep searchstring **(mM-1)
in Zsh will do the grep operation recursively (**) for all files that were modified (m) within the last month (M-1).

For anyone interested in this quite handy feature have a look here: http://zsh.sourceforge.net/Doc/Relea...name-Expansion
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep Word and Date from file T-Dub116 Linux - Newbie 8 12-12-2013 12:15 AM
[SOLVED] using grep with -r option bibiki Linux - Newbie 4 02-20-2011 12:39 PM
grep a directory with date order ust Linux - Newbie 4 02-16-2009 03:17 AM
Paragraph-option to grep TheSpork Linux - General 2 03-17-2006 02:45 AM
grep option needed ziox Linux - General 7 01-05-2005 12:02 AM


All times are GMT -5. The time now is 04:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration