Nono.MA

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 file.md
# 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.

touch text.md
chmod 777 text.md

Then we can retrieve its chmod number.

stat -f %A text.md
# 777

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

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

This method also works for directories.

BlogCodeMacosTil