Translate rwx Permissions into Octal Format in Linux

Sometimes you may find it useful to display the access rights of files or directories in octal form instead of rwx or perhaps you want to display both.

Instead of using good old ls -l command, in most modern Linux distributions (if not all) you will find stat, an utility that displays file or filesystem status.

When run without arguments but followed by a given filename, stat will display a good deal of information about the file or directory. If used with the -c option, stat allows you to specify an output format. It is precisely this option that’s of particular interest to us.

To display all files in the current working directory followed by the access rights in octal form, type:

# stat -c '%n %a' *
Sample Output
add_emails.sh 755
anaconda-ks.cfg 600
delete_emails.sh 755
employee-dump.sql 644
index.html 644
latest.tar.gz 644
nrpe-2.15.tar.gz 644
php7 644
playbook.retry 644
Find Linux File Permissions in Octal Format

Find Linux File Permissions in Octal Format

In the command above, the format sequence:

  1. %n – means file name
  2. %a – means access rights in octal form

Alternatively, you can append %a to %A, the argument passed to stat if you want to display the permissions in rwx format as well.

In that case, you can type:

# stat -c '%n %A' *
Sample Output
add_emails.sh -rwxr-xr-x
anaconda-ks.cfg -rw-------
delete_emails.sh -rwxr-xr-x
employee-dump.sql -rw-r--r--
index.html -rw-r--r--
latest.tar.gz -rw-r--r--
nrpe-2.15.tar.gz -rw-r--r--
php7 -rw-r--r--
playbook.retry -rw-r--r--
Find Linux File Permissions in Directory

Find Linux File Permissions in Directory

To view the file type in the output, you can add %F format sequence.

# stat -c '%c %F %a'

There are several other format sequences you can specify, refer to the stat man page to find out more.

# man stat

In this tip, we have covered an important Linux utility called stat, that helps you to display a file or file system status. Our main focus here was to translate the rwx access rights from the traditional ls -l output to octal form.

As I had mentioned earlier on, many modern Linux distributions now come with stat utility. But you must also remember that your shell may come with its own version of stat, therefore refer to your shell’s documentation for more information concerning options and how to use them.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

6 Responses

  1. Alexandre de Moraes says:

    Thank you very much, very useful.

  2. mohammad says:

    Hi. Thanks for your good post, but the below command is wrong : (-F)

    # stat -c '%c -F %a'
    

    Correct command is :

    # stat -c '%c %F %a'
    

    Please correct the command..

    Best Regards

Leave a Reply to Ravi Saive Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.