For a unix file, I want to know if Group or World has write permission on the file.
I’ve been thinking on these lines:
my $fpath = "orion.properties";
my $info = stat($fpath) ;
my $retMode = $info->mode;
$retMode = $retMode & 0777;
if(($retMode & 006)) {
# Code comes here if World has r/w/x on the file
}
Thanks.
You are close with your proposal – the usage of
statis a little off (but on second thoughts, you must be usingFile::stat; it helps if your code is complete), the mask constant is faulty, and the comment leaves somewhat to be desired:The terminology in the question title ‘How to check in Perl if the file permission is greater than 755? i.e. Group/World has write permission’ is a little suspect.
The file might have permissions 022 (or, more plausibly, 622), and that would include group and world write permission, but neither value can reasonably be claimed to be ‘greater than 755’.
A set of concepts that I’ve found useful is:
For example, for a data file, I might require:
More likely, for a data file, I might require:
Directories are slightly different: execute permission means that you can make the directory your current directory, or access files in the directory if you know their name, while read permission means you can find out what files are in the directory, but you can’t access them without execute permission too. Hence, you might have:
Note that the set and reset bits must be disjoint (
($set & $rst) == 0)), the sum of the bits will always be 0777; the “don’t care” bits can be computed from0777 & ~($set | $rst).