How to get octal file permissions from command line?

Sometimes we want to know the octal number representing the permission of a file like 755, 777, 664 but the popular command ls on Linux normally just shows us things in human-readable form like drwxr-xr-x.

As such, it’s really inconvenient to not know commands that show octal permission numbers of files, especially when we want to set the permission of a file/folder the same as the permission of other folders/files.

Following are a few commands that make life easier for us.

On Ubuntu

To show the octal permission of a file, run following command

stat --format "%a" filename

To show permissions of files in the current folder in the format <human-readable> <octal> <filename>:

stat -c '%A %a %n' *

To show permissions of files in the current folder in the format of <octal> <filename>:

stat -c "%a %n" *

On mac os

To show permissions of files in the current folder in the format of <octal> <filename>:

stat -f '%A %N' *

More Articles

How to start a new Github repo from an existing project

Assume that you have a project and you want to track it with Github. Navigate to the project folder,...

codezilla

codezilla

How to check for listening ports in Linux

Here is one of the most popular commands for troubleshooting network or specific application problem...

codezilla

codezilla