Ubuntu – How to get octal file permissions from command line

command linepermissions

There is a chmod command to set file permissions, but can I get file permissions in octal mode (such as 755) from the command line?

Best Answer

You can try

stat -c "%a %n" *

Replace * with the relevant directory or the exact filename that you want to examine.

From the man page of stat,

-c  --format=FORMAT
          use  the  specified  FORMAT instead of the default; output a newline after
          each use of FORMAT
%a     Access rights in octal
%n     File name

Usage:

  • With files:

    $ stat -c "%a %n" ./Documents/Udev.html 
    664 ./Documents/Udev.html
    
  • With folders:

    $ stat -c "%a %n" ./Documents/
    755 ./Documents/
    

(Reference)