Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

File not found error

by rrrrr (Novice)
on Oct 10, 2012 at 16:42 UTC ( #998257=perlquestion: print w/ replies, xml ) Need Help??
rrrrr has asked for the wisdom of the Perl Monks concerning the following question:

i tried the below code

#!/usr/bin/perl use warnings; use strict; my $wkDir; $wkDir ="/D/ARCHIVE/BIOS/PRTFILES"; system("find . -mtime +20 -type d \"${wkDir}\" -exec rm -rf {} \\;");

Its showing the below error.

/D/ARCHIVE/BIOS/PRTFILES Access denied - . File not found - -MTIME File not found - +20 File not found - -TYPE File not found - D File not found - -EXEC File not found - RM File not found - -RF File not found - {} File not found - \;

Can anyone help to solve this error?

Comment on File not found error
Download Code
Replies are listed 'Best First'.
Re: File not found error
by aitap (Deacon) on Oct 10, 2012 at 17:08 UTC

    Well, first of all, your find syntax is incorrect (did you mean to specify ${wkDir} earlier in the command line?).

    Secondly, you should use safer list variant of system: system(qw/find . -mtime +20 -type d/,$wkDir,qw/-exec rm -rf {} ;/); (in this case the qw// operator splits the line in a list and passes all arguments safely straight to find not invoking any shell).

    Thirdly, you didn't state what did you want to do. Please read How do I post a question effectively? and XY Problem and tell us what you wanted to achieve using this command.

    Sorry if my advice was wrong.

      Hi aitap

      I want one liner command to delete non empty directories older than days. So tried of find command. I want to pass the path name and no of days through a find command. I searched hardly I couldnt find anything.

        man find:

        SYNOPSIS find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [express +ion] <...> find: paths must precede expression
        So, first, move all your paths to search into before any expressions. Next, replace -exec rm -rf {} ; with -ls in order to debug your expression and make sure it finds only what you want to delete. Next, run and check that your command runs and returns expected results. Finally, move -exec rm -rf {} ; back in its place.

        You can also use find2perl to make a Perl program from find expression or start manually using File::Find instead.

        Sorry if my advice was wrong.
Re: File not found error
by Anonymous Monk on Oct 10, 2012 at 16:53 UTC

    "Access Denied" it says.

    Have you considered giving the current user permission to do those operations?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://998257]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (19)
As of 2015-07-29 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls