I assume that you want to check the permission of the file
Fcntl':mode' module contains all the constants and functions you need to extract the file type and permissions.
S_IMODE is the function which helps you extract the permissions: $permissions = S_IMODE($mode);
| [reply] |
Use "use Fcntl ':mode';" to import S_I* constants. They are just bitmasks that masks bits from portions of files permissions. In Unix systems they are grouped into 4 groups of 3 bits. First three are for setuid(4), setgid(2), stickybit(1). Other three groups of bits are for user, owner group and others. Permissions are read(4), write(2) and execute(1).
Permissions are often represented in octal form, so for this permission "rwxr-x-w-" you will have octal one 0752.
I recommend you reading "perldoc -f stat" document, you have it all there. Except some of the stuff about inner working, which you could find in "info glibc" if you are working on some Linux system.
Code from stat doc page:
#!/usr/bin/env perl
use Fcntl ':mode';
use strict;
use warnings;
my $mode = (stat($ARGV[0]))[2];
my $user_rwx = ($mode & S_IRWXU) >> 6;
my $group_read = ($mode & S_IRGRP) >> 3;
my $other_execute = $mode & S_IXOTH;
printf "Permissions are %04o\n", S_IMODE($mode), "\n";
my $is_setuid = $mode & S_ISUID;
| [reply] [d/l] |
Just a quick clarification on the source of $mode in the ree's example above
perl -e 'use Fcntl qw(:mode);$permissions=S_IMODE((stat("filename"))[2
+]);print $permissions,"\n";'
| [reply] [d/l] [select] |
use Data::Dumper;
use Fcntl ':mode';
my $filename="pl_bak.pl";
my @array=lstat($filename);
$permissions = sprintf "%04o", S_IMODE($array[2]);
print "File permissions: $permissions\n";
Update
Removed a file type line. | [reply] [d/l] |
so how would I, then, turn said bit off and on? I assumed it would be something like this, but it clearly does not work:
use Fcntl ':mode';
$file = 'myfile';
$mode = (stat($file))[2];
chmod ($mode | S_IXOTH), $file;
| [reply] [d/l] |
chmod(($mode | S_IXOTH), $ARGV[0]);
| [reply] [d/l] [select] |