Blog

Display Linux octal file permissions

Any Linux user quickly becomes familiar with chmod and file permissions. While I love `ll` as much as anyone, I also wanted a quick command to be able to display Linux octal file permissions as an integer – the same number you provide to chmod. You get used to translating the commandline outputs to numbers, but I wanted something that would show permissions in integer form: 600, 755, etc. I’m using Centos / Red Hat.

Sure enough, there’s a command that does exactly this:

stat -c "%a %n"

I’ve found a fair amount of Linux folks who haven’t used this before. The provided arguments specify:

-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

I turned this into an alias I call ‘remod’:

alias remod="stat -c '%a %n'"

No more screw-ups from misreading or miscalculating file/folder permissions; remod makes it so and can easily be piped to do more interesting things…

Leave Reply