Deleting files older than a given date

Tags
dat, date, deleting, files, older, shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 12-03-2002
Deleting files older than a given date

Hi all,

I want to delete all files in a directory which are older than a given date.

I thought of doing it by creating a file by the required date by using touch command. And then i would use find command on that file and try to find files older than that.

I searched the man and found a newer option for find command.
But i didn't get the opposite of it (i would like to find older files)

Can anyone please tell me the easiest way to do that?

Thanks in advance,
raju
# 2  
Old 12-03-2002
Read your "find" man page carefully and see if "-mtime +3" is the opposite of "-mtime -3". It is in some newer versions of find, and you may have one.

This is a case where posting the result of "uname -sr" or something similar would allow those with specialized knowledge to help more.
# 3  
Old 12-04-2002
you could use the find command

eg

find /my_current_directory -mtime +5 -exec rm {} \;


Note
To find files created more than 5 days use -mtime +5
To find files created less than 5 days use -mtime -5
# 4  
Old 12-09-2002
Quote:
Originally posted by hassan2
you could use the find command

Code:
find /my_current_directory -mtime +5 -exec rm {} \;

If there are a lot of these files, you'll save time with
Code:
find /my_current_directory -mtime +5 -print | xargs rm

I.e., invoke "rm" on large groups of files --- frequently only once.
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting dated log files whihc are older than an year nanz143 Shell Programming and Scripting 13 10-23-2015 09:08 AM
Script for Deleting files older than 14 days automatically kvkreddy_b2w UNIX for Dummies Questions & Answers 1 04-07-2015 09:09 AM
How to delete all the files older than a date? Francy UNIX for Dummies Questions & Answers 1 12-16-2013 10:49 AM
Need help deleting files one week older Gangadhar Reddy Shell Programming and Scripting 2 06-18-2013 10:25 AM
Deleting Files Older than 1 hours. ooilinlove Shell Programming and Scripting 2 01-26-2013 04:39 PM
Deleting files and directory's older than 3 months mackconsult Shell Programming and Scripting 13 12-18-2012 12:11 AM
Delete log files content older than 30 days and append the lastest date log file date sreekumarhari Shell Programming and Scripting 2 11-29-2012 01:29 AM
Deleting files older than 14 days automatically samsungsamsung AIX 3 05-10-2011 01:50 PM
Deleting files older than 6 hours subhasri_2020 Shell Programming and Scripting 13 01-31-2011 03:16 PM
deleting files older than 7 days MAYAMAYA0451 Shell Programming and Scripting 1 01-03-2011 12:49 AM
Deleting older files of a particular type cmap UNIX for Advanced & Expert Users 6 09-30-2009 05:09 AM
Deleting specfic files older than N days eurouno UNIX for Dummies Questions & Answers 3 07-18-2008 11:48 PM
Deleting files older than 7 days shezam Shell Programming and Scripting 4 07-09-2008 05:40 AM
Deleting / finding files older than X days missess a day guruparan18 Shell Programming and Scripting 4 05-08-2008 07:09 AM
Deleting Files Older than 24 hours mazhar803 Solaris 7 09-27-2007 08:30 AM
All times are GMT -4. The time now is 01:50 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.