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 {} \; |
If you are going to do it that way, you don't need Perl.
Specify dirs only (-type d) Code:
find /D/archieve/Test -type d -ctime +14 -exec rm -rf {} \; If you are going to use Perl, use it as a programming lang http://perldoc.perl.org/ and lookup opendir(), readdir(), rmdir() |
Hi
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 {} \`"; Regards Ramya M |
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 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. |
system("find /D/Archieve/Test -type d -ctime +14 -exec rm -rf {} \;");.
system("find /D/Archieve/Test -ctime +14 -exec rm -rf {} ");. Its showing error . How will implement find command in system. I jst need any one liner command to delete folders using perl. Regards Ramya |
All times are GMT -5. The time now is 06:42 PM. |