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

 

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
------------------------------
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--

 

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

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)