Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to constrain the following search to only files with a modified date <= "2009-05-29 11:59:00"

find /path -name "*.sb" ! -name "*[^0-9]*.sb"  -type f -print

I'm using CentOS

share|improve this question
add comment

4 Answers 4

up vote 3 down vote accepted

The command find /path -mtime +7 will give you files older than 7 days, and find ! -newer somefile will give you files older than somefile. So...

touch -d "2009-05-29 11:59:00" timestampfile

find /path -name "*.sb" ! -name "*[^0-9]*.sb" ! -newer timestampfile -type f -print
share|improve this answer
    
or simply -mtime -1 ;) –  Alex Jurkiewicz May 30 '09 at 17:01
    
Just out of curiosity, why would anyone mark down this answer as not helpful? –  Matt Simmons May 30 '09 at 17:42
2  
The '-newermt "DATE"' is a simpler/more elegeant way if you have GNU findutils installed. This is a little more portable across various UNIX versions, though it depends on the capabilities of your touch command. –  pgs May 31 '09 at 2:41
    
To be clear: find /foo/bar/ -type f -newermt "$(date='7 days ago')" –  Stéphane Jan 22 '13 at 7:38
add comment

! -newermt '5/29/2009 23:59:00' should work on BSD; there will be a similar option on GNU.

share|improve this answer
    
Its the same switch in GNU. –  Kyle Brandt May 30 '09 at 17:19
    
yep! this one is great! work on GNU/Linux as such: find . -type f -newermt '9/13/2012 18:09:00' –  woohoo Jan 5 '13 at 23:12
add comment
find /path \
  -type f \
  ! -newermt "20090529 1159:00" \
  -regex "./[^0-9]*.sb$" \
  -print

You can place the regex at the end to speed up the command (place the fastest actions at the start, slowest at the end).

share|improve this answer
add comment

You want -mdate

find /path -name ".sb" ! -name "[^0-9]*.sb" -type f -print -mdate -2009-05-30

Here are a couple of examples:

http://www.softpanorama.org/Tools/Find/selecting_files_by_age.shtml
http://www.schuerig.de/michael/linux/snippets.html

share|improve this answer
add comment

Your Answer

 
discard

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.