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
------------------------- 755
anaconda-ks.cfg 600 755
employee-dump.sql 644
index.html 644
latest.tar.gz 644
nrpe-2.15.tar.gz 644
php7 644
playbook.retry 644


In the command above, the format sequence:

%n – means file name

%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
------------------------------ -rwxr-xr-x
anaconda-ks.cfg -rw------- -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--


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


Var dette svaret til hjelp? 0 brukere syntes dette svaret var til hjelp (0 Stemmer)