How to view octal permission of file

The ls command shows the access permissions of a file or directory in the symbolic representation using rwx. Sometimes you may want the view the permissions in octal representation. Sadly ls has no option to show this.

However, the stat command shows both the octal and symbolic representations by default amongst the other wealth of details it lists:

$ stat foobar.txt
  File: β€˜foobar.txt’
  Size: 1692            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 57285082    Links: 1
Access: (0400/-r--------)  Uid: ( 1001/  joe)   Gid: ( 1001/  joe)
Access: 2016-05-11 15:16:32.884351709 +0800
Modify: 2016-05-11 13:42:04.135990274 +0800
Change: 2016-05-11 15:16:31.872327471 +0800
 Birth: -

To get just the permissions in octal representation:

$ stat --format="%a" foobar.txt

Tried with: Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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