If you want to see all 4096 possible file permissions, the following code will generate each of them in the directory of your choice (named '0nnnn_xxxxxxxxx.txt', where '0nnnn' is the octal permission, and 'xxxxxxxxx' is the string form of the permissions). (Each file contains only the text of its file name, including the provided path.)
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Data::Dumper;
use File::Path;
use File::Spec;
use Getopt::Long;
$Data::Dumper::Deepcopy = 1;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Useqq = 1;
$| = 1;
srand();
my ( $_DEBUG, $_TEST, $_VERBOSE, ) = ( 0, 0, 0, );
my $create_dir = 0;
my $target_dir = q{.};
GetOptions(
q{debug!} => \$_DEBUG,
q{test!} => \$_TEST,
q{verbose!} => \$_VERBOSE,
q{create_dir!} => \$create_dir,
q{target_dir:s} => \$target_dir,
q{help} => sub { &help; },
);
sub help {
print <<HELP;
Usage:
$0 [--help]
$0 [--option1 [--option2 param] ...]
Options:
--help - Display help text and exit.
--create_dir - Create directory if it does
not exist.
--target_dir path/to/target - Directory to create files.
--debug - Enable some debug output.
--test - Enable some test code.
--verbose - Increase verbosity.
HELP
exit;
}
if ( !-e $target_dir ) {
if ( !$create_dir ) {
die
qq{Target directory $target_dir does not exist, but missing '--create_
+dir' option.\n};
}
my @created = File::Path::make_path(
$target_dir,
verbose => $_VERBOSE,
mode => oct(q{0711}),
) or die $!;
print qq{Created:\n}, map { qq{\t} . $_ . qq{\n}; } @created
if ($_VERBOSE);
}
my %known = (
oct_00000 => oct(q{00000}),
oct_00001 => oct(q{00001}),
oct_00002 => oct(q{00002}),
oct_00004 => oct(q{00004}),
oct_00007 => oct(q{00007}),
oct_00010 => oct(q{00010}),
oct_00020 => oct(q{00020}),
oct_00040 => oct(q{00040}),
oct_00070 => oct(q{00070}),
oct_00100 => oct(q{00100}),
oct_00200 => oct(q{00200}),
oct_00400 => oct(q{00400}),
oct_00700 => oct(q{00700}),
oct_01000 => oct(q{01000}),
oct_02000 => oct(q{02000}),
oct_04000 => oct(q{04000}),
oct_07000 => oct(q{07000}),
);
my %shift_right = (
q{0_special} => 9,
q{1_user} => 6,
q{2_group} => 3,
q{3_other} => 0,
);
foreach my $i (
$known{oct_00000} .. (
$known{oct_07000} | $known{oct_00700} |
$known{oct_00070} | $known{oct_00007}
)
)
{
my %perm = (
raw_octal => $i,
octal => {
q{0_special} => 0,
q{1_user} => 0,
q{2_group} => 0,
q{3_other} => 0,
},
str => {
q{1_user} => q{---},
q{2_group} => q{---},
q{3_other} => q{---},
},
);
$perm{octal}{q{0_special}} = ( $i & $known{oct_07000} );
$perm{octal}{q{1_user}} = ( $i & $known{oct_00700} );
$perm{octal}{q{2_group}} = ( $i & $known{oct_00070} );
$perm{octal}{q{3_other}} = ( $i & $known{oct_00007} );
foreach my $k (qw/ 0_special 1_user 2_group 3_other /) {
$perm{octal_value}{$k} =
( $perm{octal}{$k} >> $shift_right{$k} );
}
foreach my $k (qw/ 1_user 2_group 3_other /) {
substr( $perm{str}{$k}, 0, 1 ) = q{r}
if ( ( $perm{octal_value}{$k} & $known{oct_00004} ) ==
$known{oct_00004} );
substr( $perm{str}{$k}, 1, 1 ) = q{w}
if ( ( $perm{octal_value}{$k} & $known{oct_00002} ) ==
$known{oct_00002} );
substr( $perm{str}{$k}, 2, 1 ) = q{x}
if ( ( $perm{octal_value}{$k} & $known{oct_00001} ) ==
$known{oct_00001} );
}
if ( ( $perm{octal_value}{q{0_special}} & $known{oct_00004} )
== $known{oct_00004} )
{
substr( $perm{str}{q{1_user}}, 2, 1 ) = q{S};
substr( $perm{str}{q{1_user}}, 2, 1 ) = q{s}
if (
(
$perm{octal_value}{q{1_user}} & $known{oct_00001}
) == $known{oct_00001}
);
}
if ( ( $perm{octal_value}{q{0_special}} & $known{oct_00002} )
== $known{oct_00002} )
{
substr( $perm{str}{q{2_group}}, 2, 1 ) = q{S};
substr( $perm{str}{q{2_group}}, 2, 1 ) = q{s}
if (
(
$perm{octal_value}{q{2_group}} &
$known{oct_00001}
) == $known{oct_00001}
);
}
if ( ( $perm{octal_value}{q{0_special}} & $known{oct_00001} )
== $known{oct_00001} )
{
substr( $perm{str}{q{3_other}}, 2, 1 ) = q{T};
substr( $perm{str}{q{3_other}}, 2, 1 ) = q{t}
if (
(
$perm{octal_value}{q{3_other}} &
$known{oct_00001}
) == $known{oct_00001}
);
}
my $str = q{};
$str .= sprintf qq{%05o }, $perm{raw_octal};
$str .= q{= };
$str .= sprintf q{%05o | %05o | %05o | %05o },
$perm{octal}{q{0_special}}, $perm{octal}{q{1_user}},
$perm{octal}{q{2_group}},
$perm{octal}{q{3_other}};
$str .= q{= };
$str .= sprintf q{%3s%3s%3s}, $perm{str}{q{1_user}},
$perm{str}{q{2_group}}, $perm{str}{q{3_other}};
print Data::Dumper->Dump( [ \%perm, ], [ qw( *perm ), ], ),
qq{\n}
if ($_DEBUG);
print $str, qq{\n} if ($_VERBOSE);
my $fn = sprintf qq{%05o_%s.txt}, $perm{raw_octal},
join( q{},
$perm{str}{q{1_user}},
$perm{str}{q{2_group}},
$perm{str}{q{3_other}},
);
$fn = File::Spec->catfile( $target_dir, $fn ) or die $!;
if ( !$_TEST ) {
if ( !-f $fn ) {
open my $fh, q{>}, $fn or die $!;
print $fh $fn, qq{\n};
close $fh;
}
chmod $perm{raw_octal}, $fn or die $!;
}
}