Recursive chmod/chown

  • Thread starter Christopher W Aiken
  • Start date
C

Christopher W Aiken

In UNIX a simple "-R" option on the "chmod/chgrp/chown" command
will traverse all files and directories. Is there a simple way of
doing this same thing is a Perl script?

-=[cwa]=-
 
P

Paul Lalli

Christopher said:
In UNIX a simple "-R" option on the "chmod/chgrp/chown" command
will traverse all files and directories. Is there a simple way of
doing this same thing is a Perl script?

Not quite as simple, no, but still relatively painless:

use File::Find;
find ( sub { chmod 0755, $_ or warn "Cannot chmod $File::Find::name:
$!"; }, '.');

Read more about File::Find at:
perldoc File::Find

Paul Lalli
 
I

Ian Wilson

Christopher said:
In UNIX a simple "-R" option on the "chmod/chgrp/chown" command
will traverse all files and directories. Is there a simple way of
doing this same thing is a Perl script?

File::Find ?
 
C

Christopher W Aiken

Not quite as simple, no, but still relatively painless:

use File::Find;
find ( sub { chmod 0755, $_ or warn "Cannot chmod $File::Find::name:
$!"; }, '.');

Read more about File::Find at:
perldoc File::Find

Paul Lalli


Thanks !!! Doesn't look too bad to code.

-=[cwa]=-
 
G

Gunnar Hjalmarsson

Paul said:
Not quite as simple, no, but still relatively painless:

use File::Find;
find ( sub { chmod 0755, $_ or warn "Cannot chmod $File::Find::name:
$!"; }, '.');

Read more about File::Find at:
perldoc File::Find

Alternatively you can make use of the UNIX feature:

system "chmod -R 0755 $dir"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top