Show the octal file permissions from Linux command line and Mac terminal


Mon, 23 March 2020

It's helpful to have an understanding of file permissions on a unix system. I've seen all too regularly someone just wildly issue a 777 of an entire directory.

Performing just a list of files, for example with `ls -la` or for those of us who use aliases, `ll`.

Thankfully, there's a much easier way. It's called `stat`.


On a Linux system you'd issue:

$ stat -c '%a' /the/path/to/the/file.txt

Which would output something like:

0600

Using the terminal on a Mac, you could achieve the same thing by issuing:

$ stat -f '%A' /the/path/to/the/file.txt

Which, like above would output the octal number like this:

0600

Clearly, you could also add this to your bash aliases. To refresh, the format for Linux is:

alias perm="stat -c '%a'"

The format for Mac is:

alias perm="stat -f '%A'"