Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How do I test the permissions of a file for user, group, and all?

by chicks (Scribe)
on Apr 21, 2002 at 15:36 UTC ( [id://160886]=note: print w/replies, xml ) Need Help??


in reply to How do I test the permissions of a file for user, group, and all?

Here's a script that shows how to use stat to get what you're looking for and an example invocation.
$ cat fileperm #!/usr/bin/perl my $filename = 'fileperm'; my $mode = (stat $filename)[2]; $mode = $mode & 07777; # mask off file type; my $usr = ($mode & 0700) >> 6; my $grp = ($mode & 0070) >> 3; my $oth = $mode & 0007; printf "$filename has permissions %04o (%i,%i,%i)\n", $mode, $usr, $gr +p, $oth; $ ./fileperm fileperm has permissions 0775 (7,7,5) $ ls -l fileperm -rwxrwxr-x 1 chicks chicks 289 Apr 21 11:32 fileperm
  • Comment on Re: How do I test the permissions of a file for user, group, and all?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://160886]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found