Solved

deleting file and directories older than 30 days

Posted on 2001-09-10
6
201 Views
Last Modified: 2012-05-05
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
Comment
Question by:sushrut
6 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 6472641
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
 
LVL 5

Accepted Solution

by:
Droby10 earned 50 total points
ID: 6472808
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
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 6475536
Has this helped??
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:sushrut
ID: 6476788
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
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 6478189
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
 
LVL 3

Expert Comment

by:iPromoExpert
ID: 23009180
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
binary to char / hexadecimal 5 98
Perl for loop for 2000 ms 7 92
Regex rule to match two different url 5 38
Perl tar error 8 32
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now