Command to return permissions in octal format

Is there any command that would return the permissions of a file or folder in octal format (e.g. 755, 644, etc.)

Thanks

A quick search for octal permissions reveals your answer!

Display Permissions in Octal

-Enjoy
fh : )_~

try the following:

find /directory/to/check/ filestocheck -printf '%m \n'

Hi,

Thanks for the answers

@Fetus Hagen

I checked out that thread and tried this command that was mentioned:

perl -e'printf "%o\n",(stat shift)[2] & 07777' FILENAME

The problem is I get this error "-bash: fork: Resource temporarily unavailable
" no matter what the file is.

@Leppie,

I'm running Mac OS X, and the find utility doesn't have -printf as an option :frowning:

EDIT: the perl command works after a restart. Weird O.o

Try this, Thanks goto Jimbo, I have modded it slightly.

#!/bin/sh

ls -ld "${1:-"*"}" | awk 'BEGIN {
v["r1"]=400; v["w2"]=200; v["x3"]=100; v["s3"]=4100; v["S3"]=4000
v["r4"]=40 ; v["w5"]=20 ; v["x6"]=10 ; v["s6"]=2010; v["S6"]=2000
v["r7"]=4  ; v["w8"]=2  ; v["x9"]=1  ; v["t9"]=1001; v["T9"]=1000}
{val=0
 for (i=1;i<=9;i++) val=val+v[substr($0,i+1,1)i]
 printf "%4d %s\n",val,$NF}'

What I did...

From this:

ls -ld $* | awk 'BEGIN {

To this

ls -ld "${1:-"*"}" | awk 'BEGIN {

-Enjoy
fh : )_~

---------- Post updated at 11:13 PM ---------- Previous update was at 10:54 PM ----------

I just noticed you use bash, I do not, I tried it in bash and it appears what I did broke it under bash.

Sorry!

-Enjoy
fh : )_~