How to tell what the CHMOD value of a file/directory is

chmod alters the permissions for a file or directory, you could allow full read/write access to a file or directory by running the following command:

chmod 777 myfile.ext
Code language: Bash (bash)

You could do the same on a directory recursively:

chmod -R 777 mydirectory
Code language: Bash (bash)

But if we look at the directory listing of this path now, we can’t tell what integer value this affected:

$ ls -lash 0 -rwxrwxrwx 1 ao staff 0B 18 Nov 13:29 myfile.ext
Code language: Bash (bash)

How to get the CHMOD value

If we want to get the actual integer value back, we could use the stat command and tell it what we want from it:

Each of the below command will now return a 777 back.

On Mac

stat -f "%OLp" myfile.ext # 777
Code language: Bash (bash)

On Linux

stat --format '%a' myfile.ext # 777
Code language: Bash (bash)

On Busybox!

stat -c '%a' myfile.ext # 777
Code language: Bash (bash)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments