LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-06-2004, 07:24 PM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,436

Rep: Reputation: 38
need a perl script to remove folders


Hi

I'm looking for a perl script to remove in a directory
all folders ( with different names ) older then 14 days.

kind regards
cccc
 
Old 03-06-2004, 08:35 PM   #2
mhiggins
Member
 
Registered: Feb 2004
Posts: 140

Rep: Reputation: 15
I don't have the time to write it all up but here are some hints and some code.

#!/usr/bin/perl

use strict;
use File::stat;
use POSIX;

my $stat_obj = stat("stattest.pl");

print "mtime: " . $stat_obj->mtime() . "\n";
print "Formatted: " . strftime("%D", localtime($stat_obj->mtime())). "\n";


not sure if this runs should ? Also you don't have to use the File::stat obj I just like that interface better than some big array that you get using the standard perl stat funtion. For more info try
perldoc File::stat
perldoc -f stat

-Matt
 
Old 03-11-2004, 08:13 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
must it be perl?

what about:

find . -type d -ctime +14 -exec rm -f {} \;

(maybe -atime ?)
 
Old 03-11-2004, 11:10 AM   #4
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,436

Original Poster
Rep: Reputation: 38
thanks !

greetings
cccc

Last edited by cccc; 03-11-2004 at 11:44 AM.
 
Old 03-12-2004, 02:26 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
That should work.
rm -f

will delete a directory.


billy
 
Old 03-12-2004, 02:39 AM   #6
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,436

Original Poster
Rep: Reputation: 38
to delete not empty directories I did:

find /var/tmp -type d -ctime +14 -exec rm -rf {} \{\} \;

kind regards
cccc
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
unable to remove files/folders timsch75 Linux - Software 2 03-01-2004 11:01 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM
How to remove sites once you have put them into folders Silverw0lf Linux - Newbie 1 10-18-2003 01:33 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM


All times are GMT -5. The time now is 09:04 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration