Listing Octal Numerical File Permissions in Linux

Submitted by nigel on Friday 29th April 2011

The other day I needed the output of a directory on Linux showing the octal file permissions. It got me thinking - exactly how do I achieve this? The obvious solution would be the ls command, but a quick read of its man page suggested it couldn't be achieved that way.

In fact, the answer is with the stat command. The following syntax is required:

stat -c "%a %n" *

The -c flag says use the following format, whilst the format itself is:
%a Access rights in octal
%n File name.

So, a typical example would be:

badzilla@laptop4:/srv/www/htdocs/clean/sites/all/modules/tester> stat -c "%a %n" *
644 tester.module
blog terms