Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by sherifradwan (Initiate)
on Apr 17, 2002 at 17:23 UTC ( [id://159906]=perlquestion: print w/replies, xml ) Need Help??

sherifradwan has asked for the wisdom of the Perl Monks concerning the following question:

How do I test the permission of a file for user, group, and all?

Originally posted as a Categorized Question.

  • Comment on How do I test the permissions of a file for user, group, and all?

Replies are listed 'Best First'.
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
    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
Re: How do I test the permissions of a file for user, group, and all?
by particle (Vicar) on Apr 17, 2002 at 17:44 UTC
Re: How do I test the permissions of a file for user, group, and all?
by ehdonhon (Curate) on May 09, 2002 at 20:24 UTC
    print "Testing File: $test_file\n"; my ( $mode, $uid ) = (stat( $test_file ))[2,4] or die "Stat failed.\n" +; my ( $ownername ) = getpwuid $uid; print "File is owned by '$ownername'\n"; my $ms = 'xwrxwrxwr'; my $modestring; for ( 0..8 ) { if ( $mode & ( 2 ** $_ ) ) { $modestring = substr( $ms, $_ , 1 ) . $modestring; } else { $modestring = '-' . $modestring; } } print "File permissions are $modestring\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-16 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found