Get the chmod number of a folder on macOS

JULY 1, 2022

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

stat -f %A directory/
# 755

Set chmod value and read its string and numerical value

Let's give it a try.

First, create a new directory and set its permissions.

mkdir directory/
chmod 777 directory/

Then we can retrieve its chmod number.

stat -f %A directory/
# 777

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

ls -n
# drwxr-xr-x 2 501 20 64 Jun 21 13:57 directory/

This method also works for files.