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

0 min read 139 words

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

You could do the same on a directory recursively:

chmod -R 777 mydirectory

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

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

On Linux

stat --format '%a' myfile.ext

# 777

On Busybox!

stat -c '%a' myfile.ext

# 777
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags