• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

deleting file and directories older than 30 days

How can I delete files and directory and subdirectory which are older than 30 days.
ie. which are not modified in more than 30 days.
all these directories are under
/testlog/testsyste/ directory.
0
sushrut
Asked:
sushrut
1 Solution
 
Kim RyanIT ConsultantCommented:
This has been answered lots of times before (its worth searching through the previous answers). You can save some points by looking at http://www.experts-exchange.com/jsp/qShow.jsp?qid=20118133
0
 
Droby10Commented:
another alternative would be to execute the unix find command with the appropriate args.

# removes files older than 30 days recusively from the basepath

$basepath = /testlog/testsyste/
$daysold = 30
find $basepath -ctime $daysold -exec rm {} \;
0
 
Kim RyanIT ConsultantCommented:
Has this helped??
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sushrutAuthor Commented:
I was doing similer thing..
find $basepath -ctime $daysold -exec rm {} \;
but without giving '\'
any way,
I will test this code and give you points.

I am out for some training for next  7 days.
I will give you ponts when I go to office..
thanks a lot..
and sorry for late in checking the output and giving you points..

0
 
Kim RyanIT ConsultantCommented:
Keep in mind that rm is a Unix specific commnad. If you want to make your code portablr, you need to use the perl unlink command to remove files.
0
 
iPromoExpertCommented:
I used


find . -mtime +30 -exec rm {} \;


the +30 stands for anything older then 30 days, and i use -mtime finding the last modified time. lastly the find . states that you are finding everything from the current directory, or "pwd"
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now