Fedora Linux Support Community & Resources Center
  #1  
Old 19th January 2006, 12:44 PM
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
[SOLVED]Find files older than a certain date

What do you guys use to find files older that a certain date from the command line ?

Last edited by giulix; 19th January 2006 at 02:28 PM.
Reply With Quote
  #2  
Old 19th January 2006, 01:33 PM
RedFedora Offline
Registered User
 
Join Date: May 2004
Posts: 503
Depending on your style, you can use a number of flags. The
common ones in my case are:
-mmin -mtime

For example, let's find files changed in the
last five minutes:

find /mydir -mmin -5

For files changed exactly one week (7 days) ago:

find /mydir -mtime 7

Use "man find" for more details.
__________________
Registered Linux User # 373325
Reply With Quote
  #3  
Old 19th January 2006, 01:50 PM
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
Thanks. What I need is a command that allows me to select files from one or more directories for which I don't know the exact modification/access time, though. For example, a command to clean up a directory of all .log files that have modification time older than 5 days ago.
What I have now is this script
Code:
#!/bin/sh
#
# This script can be used to filter files which have a last modification date
# ('ls -ltr --time-style=long-iso' format) between a lower and an upper date.
# Example:
#   ls -ltr --time-style=long-iso | bw 2004-06-01 00:00:00 2004-06-30 23:59:59
#   This will print all files modified in June 2004.
#
awk -v d1=$1 -v t1=$2 -v d2=$3 -v t2=$4 \
'BEGIN {\
  start=sprintf("%s %s", d1, t1);\
  end=sprintf("%s %s", d2, t2);\
  gsub("-|:", " ", start);\
  gsub("-|:", " ", end)\
}\
{\
  this=sprintf("%s %s:00", $6, $7);\
  gsub("-|:", " ", this);\
  if(mktime(this) >= mktime(start) && mktime(this) <= mktime(end))\
    print $0\
}'
But cannot be deployed on the machines I intend to use it for.

Last edited by giulix; 19th January 2006 at 01:55 PM.
Reply With Quote
  #4  
Old 19th January 2006, 02:14 PM
RedFedora Offline
Registered User
 
Join Date: May 2004
Posts: 503
This should delete all files (in /var/log/) which have not been
modified in the last five days.

find /var/log/ -mtime +5 -exec rm {} \;
__________________
Registered Linux User # 373325
Reply With Quote
  #5  
Old 19th January 2006, 02:25 PM
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
Excellent !!! That did the trick. Thank you so much, RedFedora
Reply With Quote
Reply

Tags
date, files, older

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to find older fedora kernels ? cuban_cigar Using Fedora 1 29th July 2008 12:21 AM
how to find out date - 1 anitha2324 Using Fedora 2 4th March 2008 11:00 AM
how to find date??? yiela Using Fedora 9 13th July 2007 09:11 AM
find the date of the previous day mndar Using Fedora 1 23rd October 2005 07:10 PM
How to find creation date philip_w Using Fedora 4 22nd June 2005 06:15 PM


Current GMT-time: 02:49 (Monday, 22-12-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
...Kpopstay - Little Munich (Dntn Lake Worth) Photos on Instagram - Royal Troon Golf Club Instagram Photos - Piazza Sant'Eustorgio - Corso di Porta Ticinese - Fonteverde Natural Spa Resort Photos