Home » Infrastructure » Unix » How to delete files from a folder, which is older then 10 days?
How to delete files from a folder, which is older then 10 days? [message #207803] Thu, 07 December 2006 01:33 Go to next message
vishal.majithia
Messages: 3
Registered: December 2006
Location: Mumbai
Junior Member

Hi,

Can anyone help me how to delete files from unix folder, which are 10 days older????

Please...its urgent.....

Thanks in advance...
Vishal M.
Re: How to delete files from a folder, which is older then 10 days? [message #207805 is a reply to message #207803] Thu, 07 December 2006 01:39 Go to previous messageGo to next message
Frank Naude
Messages: 4502
Registered: April 1998
Senior Member
Try someting like this (but test on non-prod first!):

$ find /my/unix/folder -atime +10 -exec rm -f {} \;
Re: How to delete files from a folder, which is older then 10 days? [message #210802 is a reply to message #207805] Fri, 22 December 2006 07:54 Go to previous messageGo to next message
vishal.majithia
Messages: 3
Registered: December 2006
Location: Mumbai
Junior Member

Hi All,

Finally, I got the solution and you need to use the syntax something like mentioned below....

find 'Your File Path Name' -name '*.dat' -atime +10 -exec rm -f {} \;
Re: How to delete files from a folder, which is older then 10 days? [message #211680 is a reply to message #210802] Sun, 31 December 2006 04:55 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member
Vishal,
Did you ever come back to check the solution, after posting your question? Because Frank replied your question on 7th december, the day when you posted the qestion and i do not see much difference between Frank's solution and the answer you got.
Anyway, Enjoy posting....
Re: How to delete files from a folder, which is older then 10 days? [message #212139 is a reply to message #207803] Wed, 03 January 2007 23:52 Go to previous messageGo to next message
bsureysh
Messages: 17
Registered: January 2007
Location: india
Junior Member
rm -f `find "directorypath" -name '*.txt' -atime -10`

Chk this ..!!
Re: How to delete files from a folder, which is older then 10 days? [message #215766 is a reply to message #212139] Tue, 23 January 2007 17:39 Go to previous messageGo to next message
kalgally
Messages: 1
Registered: January 2007
Location: SJ
Junior Member
Try this.

To find the files older than 10 days:

find . -mtime +10 -print|xargs ls -l|more

To remove files older than 10 days :

find . -mtime +10 -print|xargs rm
Re: How to delete files from a folder, which is older then 10 days? [message #323690 is a reply to message #215766] Thu, 29 May 2008 04:36 Go to previous messageGo to next message
anilalkg
Messages: 1
Registered: May 2008
Junior Member
OR else you can use this perl script to have better control

********



my $dir = '/data/tmp/cvsbackup';
$dir='/export/home/tmp/akg'; # Remove later
opendir(DIR,$dir) || die "Can't open $dir : $!\n";
my @files = readdir(DIR); # you may want to grep only certain files here
close(DIR);

foreach my $file(@files)
{
my $now = time;
my @stat = stat("$dir/$file");

if ($stat[9] < ($now - 864000))
{
logMsg( "Deleting $dir/$file...");
#unlink("$dir/$file"); # Remove later
logMsg("Done.\n");
}

}


Re: How to delete files from a folder, which is older then 10 days? [message #323894 is a reply to message #207803] Thu, 29 May 2008 23:44 Go to previous message
BlackSwan
Messages: 25050
Registered: January 2009
Location: SoCal
Senior Member
>OR else you can use this perl script to have better control
"better" as measured by what metric to what accuracy?
Previous Topic: how to set ORACLE_HOME
Next Topic: to set ORACLE_HOME & ORACLE_SID
Goto Forum:
  


Current Time: Fri Dec 09 15:52:22 CST 2016

Total time taken to generate the page: 0.30486 seconds