in reply to To Delete folders older than 14 days.-Want one liner command

G'day rrrrr,

Welcome to the monastery.

Firstly, I'd recommend using something like ls -l instead of rm -rf while you're testing: avoid accidentally deleting the wrong files.

Backticks (`...`) are interpolating quotes in Perl - you don't need the surrounding double quotes. To identify directories, use -type d in the find command. I'm not sure what \{\} \ is doing: I'd use \\; in that position.

Putting all that together, this works for me:

my $command = `find . -type d -ctime +14 -exec ls -l {} \\;`;

Unless you want to capture the output from the find command, consider using system instead of backticks.

You also might like to take a look at Perl's file test operators: -M, -A and -C.

-- Ken

Replies are listed 'Best First'.
Re^2: To Delete folders older than 14 days.-Want one liner command
by rrrrr (Novice) on Sep 17, 2012 at 05:37 UTC

    Kcott thanks for ur reply. I tried as u suggested but below code showing parameter not correct error. Kindly help me . And I used ls-l its not recognized. Regards rrrrr

    #!/usr/bin/perl my $command=`find D/Archieve/Test -type d -mtime +14 -exec rm -rf {} \ +\;`; system $command; print $command;

      ls is one of the very first *nix commands one learns. By writing ls-l, and not seeing why that is wrong, you give the impression that you have virtually no *nix knowledge. I'd seek out a tutorial before proceeding further - perhaps ask your system administrator. You may end up doing irreparable damage using dangerous commands such as rm -rf when you don't really appear to know what you're doing.

      I suggested using system instead of backticks; not in addition to backticks. I took the time to provide you with a link to the system command; perhaps you could take the time to read the documentation it points to.

      You originally showed this path /D/archieve/Test; now you show D/Archieve/Test. (I'm even wondering whether that should be Archive or archive in the middle of the pathname.) Find out what the real pathname is before deleting directories and all their contents recursively and forcefully!

      -- Ken

        Hi Ken, Am working in Java Projects. Previosuly some Locate command was there but not deleting the folders. So I got this task to delete the archieved folder based on modification days.I am just going to implement this one line command in already written prog.So oly in search of one line command.Then I am testing in Development Region only so chnging the path and testing. When I searched I got this Find command. Am trying all ways of find command but either its showing invalid switch or parameter not correct error. Kindly asssit me.

        #!/usr/bin/perl system("find /D/maestro/TestDelete -mtime +4 -exec ls -l {} \\");