File::chmod::Recursive - Run chmod recursively against directories
Like File::chmod, but recursive with selective permissions
use File::chmod::Recursive; # Exports 'chmod_recursive' by default
# Apply identical permissions to everything
# Similar to chmod -R
chmod_recursive( 0755, '/path/to/directory' );
# Apply permissions selectively
chmod_recursive(
{
dirs => 0755, # Mode for directories
files => 0644, # Mode for files
# Match both directories and files
match => {
qr/\.sh|\.pl/ => 0755,
qr/\.gnupg/ => 0600,
},
# You can also match files or directories selectively
match_dirs => { qr/\/logs\// => 0775, },
match_files => { qr/\/bin\/\S+$/ => 0755, },
},
'/path/to/directory'
);
-
chmod_recursive(MODE, $path)
-
chmod_recursive(\%options, $path)
This function accepts two parameters. The first is either a MODE or an options hashref. The second is the directory to work on. It returns the number of files successfully changed, similar to chmod.
When using a hashref for selective permissions, the following options are valid -
{ dirs => MODE, # Default Mode for directories files => MODE, # Default Mode for files # Match both directories and files match => { qr/<some condition>/ => MODE, }, # Match files only match_files => { qr/<some condition>/ => MODE, }, # Match directories only match_dirs => { qr/<some condition>/ => MODE, }, # Follow symlinks. OFF by default follow_symlinks => 0, # Depth first tree walking. ON by default (default _find_ behavior) depth_first => 1, }
In all cases the MODE is whatever File::chmod accepts.
-
rchmod
-
chmodr
This is an alias for
chmod_recursive
and is exported only on request.
Please report any bugs or feature requests at https://github.com/mithun/perl-file-chmod-recursive/issues.
- chmod
- Perl Monks thread on recursive perl chmod
Mithun Ayachit <[email protected]>
Copyright (c) 2014, Mithun Ayachit <[email protected]>
. All rights
reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.