LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
  Search this Thread
Old 03-06-2004, 08:24 PM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Rep: Reputation: 50
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, 09: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, 09:13 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
must it be perl?

what about:

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

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

Original Poster
Rep: Reputation: 50
thanks !

greetings
cccc

Last edited by cccc; 03-11-2004 at 12:44 PM.
 
Old 03-12-2004, 03:26 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

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

will delete a directory.


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

Original Poster
Rep: Reputation: 50
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



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 11:22 AM
unable to remove files/folders timsch75 Linux - Software 2 03-01-2004 12:01 PM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 07:25 PM
How to remove sites once you have put them into folders Silverw0lf Linux - Newbie 1 10-18-2003 02:33 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 06:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:04 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration