Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Linux/Display Octal Permissions

February 26, 2017

Display Octal Permissions

If you’re working on the command line, listing a directory to display permissions of files is not always the most user-friendly. Here’s an example of listing the files in a directory using the ‘ls -al’ command.

$ ls -al
total 20
drwxrwsr-x  2 ulysses www-data 4096 Feb 26 13:31 .
drwxrwsr-x 10 ulysses www-data 4096 Feb 26 02:30 ..
-rw-rw-r--  1 ulysses www-data    0 Feb 26 13:31 display.txt
-rwxrwxr-x  1 ulysses ulysses   659 Dec  3 06:40 sync_com.sh
-rw-r--r--  1 ulysses ulysses   181 Feb 26 13:26 sync_db.sh
-rwxrwxr-x  1 ulysses ulysses   244 Feb 26 13:23 sync_s3.sh

$ ls -al total 20 drwxrwsr-x 2 ulysses www-data 4096 Feb 26 13:31 . drwxrwsr-x 10 ulysses www-data 4096 Feb 26 02:30 .. -rw-rw-r-- 1 ulysses www-data 0 Feb 26 13:31 display.txt -rwxrwxr-x 1 ulysses ulysses 659 Dec 3 06:40 sync_com.sh -rw-r--r-- 1 ulysses ulysses 181 Feb 26 13:26 sync_db.sh -rwxrwxr-x 1 ulysses ulysses 244 Feb 26 13:23 sync_s3.sh

There has to be a better way to display permissions?

Well, there is. It’s a command called “stat” that displays the detailed status about a file or file system. On one of the switches of the stat command, is an option that allows you to display the file status in human readable format. Here’s an example using the stat from the command line.

$ stat -c '%A %a %n' *
664 display.txt
775 sync_com.sh
644 sync_db.sh
775 sync_s3.sh

$ stat -c '%A %a %n' * 664 display.txt 775 sync_com.sh 644 sync_db.sh 775 sync_s3.sh

The result is a list of files in a directory with the file permissions in human readable format!

Filed Under: Linux Tagged With: ls, permissions, stat

About Me

I'm Ulysses, a Cloud Engineer at Cardinal Health based in Columbus, Ohio. I’m a certified AWS Solutions Architect. This website is my way of documenting the things I have learned in the Cloud. When off the grid, I enjoy riding my electric skateboard. I have surfed, snowboarded and played the saxophone in the past. I hope you will find this site helpful. It's powered by WordPress and hosted in AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021