Get File Permissions in Octal Format in Linux

Get File Permissions in Octal Format in Linux

In Linux, file permissions can presented in human readable form (e.g. drwxr-xr-x) and in octal format (e.g. 755). This tutorial shows how to get file permissions in octal format in Linux.

Using ls command with -l option we can get a list of files and their permissions presented in human readable form. In order to get file permissions in octal form we can use stat command. The -c option allows to specify output format.

stat -c '%n %a' /etc/*

Output example:

/etc/adduser.conf 644
/etc/alternatives 755
/etc/apparmor 755
/etc/apparmor.d 755
/etc/apport 755
/etc/apt 755
/etc/at.deny 640
...

In order to display file permissions in both format, use the following command:

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

Output example:

/etc/adduser.conf 644 -rw-r--r--
/etc/alternatives 755 drwxr-xr-x
/etc/apparmor 755 drwxr-xr-x
/etc/apparmor.d 755 drwxr-xr-x
/etc/apport 755 drwxr-xr-x
/etc/apt 755 drwxr-xr-x
/etc/at.deny 640 -rw-r-----
...

Meaning of format specifiers:

  • %n - filename.
  • %a - file permissions in octal form.
  • %A - file permissions in human readable form.

Leave a Comment

Cancel reply

Your email address will not be published.