To delete folders older than 14 days in perl script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
To delete folders older than 14 days in perl script
Hi,
I am new to perl script. I need one line command to delete folders. So I have tried using find command in perl script to delete the folders older than 14 days. Its not showing error but not deleting the folder.
Kindly assist me
my $command="`find /D/archieve/Test -ctime +14 -exec rm -rf {} \{\} \`";
Dis code not showing error but not deleting my old folders
Sorry, but I do not understand that line.
my $command="` something `";
should execute that something and the variable command will get the return value of that command. But in your case you want to execute a find and a rm command and do not take care about the returned string.
You have a backslash before the second backtick (\`), therefore it is escaped. So this line will not work that way, because the first ` has no pair.
I do not know what is that \{\} good for. What was your intention?
The most simple way would be: find /D/archieve/Test -ctime +14 -exec rm -rf {} \;
As suggested I tried the below command. But still not working and not showing error. I want to implement unix command in Perl.I need one line command not perl prog.Kindly assist me.
#!/usr/bin/perl
"`find /D/archieve/Test -type d -ctime +14 -exec rm -rf {} \`";
That's because you are confusing shell (usually bash on Linux) with Perl.
They are completely different languages.
Decide which one you want to use and stick to it.
This
Code:
#!/usr/bin/perl
is a request to the kernel to use Perl.
The remainder is a shell cmd and does not require quotes; see my example above.
in perl you can execute any shell command by: system($command).
But again, \` is not ok at the and of your code, probably ; is missing or ?? I don't know. Also you not need backticks (`) at all with system.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.