Link to home
Start Free TrialLog in
Avatar of keithk
keithk

asked on

how to use stat() to get unix permissions?

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!
Avatar of ozo
ozo
Flag of United States of America image

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

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you really use
 $mode = stat("/test") [2]
?
I have to use $mode = (stat "/test")[2];