Results 1 to 6 of 6
Hi all,
I'm here is my problem :
How delete all files from a directory,which are created before a specific date?
For example:[user provides the no.of days = 5]
Delete ...
- 02-12-2008 #1
Shell script:How to delete based on created date ?
Hi all,
I'm here is my problem :
How delete all files from a directory,which are created before a specific date?
For example:[user provides the no.of days = 5]
Delete all files from /home/oss directory except,
those files created which are in the last 5 days.
Any thoughts?- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 02-12-2008 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try the find command with the -mtime option:
Try this first to see if you get the correct files:Code:find /home/oss -mtime +5 -exec rm -f {} \;
RegardsCode:find /home/oss -mtime +5 -exec ls -l {} \;
- 02-13-2008 #3
Thanks for your help.
provides me files which are modifed 5 days ago.Code:find /home/oss -mtime 5 -exec ls -l {} \;
But,Let me explain my problem bit more clearly:
I have 7 files created between Feb 7 to 13:
How to delete files which are created before 3 days.Code:-rw-r--r-- 1 oss oss 6770 Feb 13 11:25 access_log.someext -rw-r--r-- 1 oss oss 6770 Feb 12 11:25 access_log.something -rw-r--r-- 1 oss oss 6770 Feb 11 11:25 access_log.cf -rw-r--r-- 1 oss oss 6770 Feb 10 11:25 access_log.ad -rw-r--r-- 1 oss oss 6770 Feb 9 11:25 access_log.aw -rw-r--r-- 1 oss oss 6770 Feb 8 11:25 access_log.zsd -rw-r--r-- 1 oss oss 6770 Feb 7 11:25 access_log.xzs
ie.delete all files which are created before feb-11.
Delete following files :
Finally the directory has following files:Code:-rw-r--r-- 1 oss oss 6770 Feb 10 11:25 access_log.ad -rw-r--r-- 1 oss oss 6770 Feb 9 11:25 access_log.aw -rw-r--r-- 1 oss oss 6770 Feb 8 11:25 access_log.zsd -rw-r--r-- 1 oss oss 6770 Feb 7 11:25 access_log.xzs
These files are created between Feb 11 to 13.
Code:-rw-r--r-- 1 oss oss 6770 Feb 13 11:25 access_log.someext -rw-r--r-- 1 oss oss 6770 Feb 12 11:25 access_log.something -rw-r--r-- 1 oss oss 6770 Feb 11 11:25 access_log.cf
Thanks.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 02-13-2008 #4
Sorry i missed out '+'
It's working . Thanks franklinCode:find . -mtime +5 -exec ls -l {} \;
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 02-13-2008 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
You forgot the "+" sign. From the manpage of find:
-atime n
File was last accessed n*24 hours ago. When find figures out
how many 24-hour periods ago the file was last accessed, any
fractional part is ignored, so to match -atime +1, a file has to
have been accessed at least two days ago.
-mtime n
File's data was last modified n*24 hours ago. See the comments
for -atime to understand how rounding affects the interpretation
of file modification times.
n : exact n*24 hours ago.
-n : under n*24 hours.
+n : over n*24 hours.
Regards
- 02-13-2008 #6
yes.I agree
Thanks for your help.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------


Reply With Quote