Get the chmod number of a file on macOS

JUNE 26, 2022

Here's how to obtain the numerical value of the chmod permissions of a file on macOS. (Note that this method also works for directories.)

stat -f %A
# 755

Set chmod value and read its string and numerical value

Let's give it a try.

First, create a new file and set its permissions.

chmod 777

Then we can retrieve its chmod number.

stat -f %A
# 777

And here's how to retrieve it's chmod string value.

ls -n
# -rwxrwxrwx 1 501 20 0 Jun 21 13:53*

This method also works for directories.