3

How can I get the octal permissions for a file?

/tmp$ ls -al myfile 
-rw-r--r--  1 wim  wheel     0B Oct 20 22:31 myfile
/tmp$ the_command myfile
644 

Tried a suggestion I've found in other answers on here, and it didn't work:

/tmp$ stat -c "%a %n" myfile 
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
5

New info obtained (and shorter): stat -f '%A' <filename>
You can also use * for all files and folder. If you need them in a nicer format you can use
stat -f '%A %N' <filename> which will show the octal permission and filename.

Credit:
https://askubuntu.com/a/152003 - check the first comment of this answer
http://geeklog.adamwilson.info/article/58/getting-file-permissions-in-octal-on-OS-X


Edited to add: To check your result, try running stat -f "%Sp %OLp" <filename> which will give you the --rwxrwxrwx style + the Octal version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.