We help IT Professionals succeed at work.

how to use stat() to get unix permissions?

keithk
keithk asked
on
Medium Priority
324 Views
Last Modified: 2011-09-20
I can use:

 $mode = stat("/test") [2]

and I get a 5 digit number like 33216
HOW do I convert this number into unix permissions such
as 777 or 755 or 700?

Thanks!
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
#33216  is a unix permission number,
#you're just loking at in decimal instead of octal
printf "%o",$mode;

Author

Commented:
that did it...I though that was the problem, - so I tried to use oct()...but that is the opposite of printf format specifier!

Thanks...
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
$modedigits = sprintf "%o",$mode;
#also
$ownerread = 0400 & $mode;
#etc.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
Can you really use
 $mode = stat("/test") [2]
?
I have to use $mode = (stat "/test")[2];
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.