Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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!
0
keithk
Asked:
keithk
  • 3
1 Solution
 
ozoCommented:
#33216  is a unix permission number,
#you're just loking at in decimal instead of octal
printf "%o",$mode;
0
 
keithkAuthor 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...
0
 
ozoCommented:
$modedigits = sprintf "%o",$mode;
#also
$ownerread = 0400 & $mode;
#etc.
0
 
ozoCommented:
Can you really use
 $mode = stat("/test") [2]
?
I have to use $mode = (stat "/test")[2];
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now