Is there a specific reason you're using perl for this task? You can accomplish the same with:

find /share_folder -mtime +30 | xargs rm

but you should probably verify the correctness of the command first with

find /share_folder -mtime +30 | xargs ls

Thank you so much. Your simple script does pretty much what I needed. However, find doesn't seem to be able to traverse sub folders with spaces in between.


[EMAIL PROTECTED] transfer]# find nzhang/ -mtime +30 | xargs ls
ls: nzhang/arkon: No such file or directory

[EMAIL PROTECTED] transfer]# ls -l nzhang
total 8916
drwxrwxrwx    2 nzhang   Domain Users     4096 Feb 11 13:27 arkon icon/

Is there a way that I can go around this? Perhaps I need Perl for the more advance searching?

I don't know any way to make it work with filenames containing spaces (filenames with spaces are generally a bad idea, even on Windows). You'll probably need to use either File::Find or walk the directories manually (with opendir, readdir, closedir). You can still use the find2perl utility to generate the code for you if File::Find will work for you. Alternatively, the script John posted should work fine for your needs.

Thanks Randy for your generous help. I generated the script with
"find2perl testfl/ -mtime +30 > rmoldshares.pl", but it seems File::Find doesn't recognize foldernames with spaces. 8( Anyone know other solutions beside using manual opendir, readdir, closedir?


Regards,
Norman

#! /usr/bin/perl -w
    eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
        if 0; #$running_under_some_shell

use strict;
use File::Find ();

# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;

# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, 'testfl/');
exit;

sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);

    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    (int(-M _) > 30);
}


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to