When looking at a list of filesystem objects, I have trouble visually parsing rwxr-xr-x or similar permissions. It’s probably something with my eyes, but I’d much prefer to see 755. More than just a visual preference, somehow I just “get” it faster than seeing letters and dashes. Surely there must be some simple switch in ls that will do this, right?
However, a quick-n-dirty way of doing this is with the “stat” command using the -c switch. Stat itself will show you file or filesystem status information. The -c switch allows you to customise the output. To see file permissions in octal use the “%a” format sequence. I toss in a few other format sequences for my tastes:
stat -c "%n %a %G %g" IMG_0346.MOV IMG_0346.MOV 664 wesley 500
The file’s name is shown as a result of %n, %a shows octal permissions, %G shows the owner’s group name and %g shows the owner’s group ID.
To see the octal permissions of the contents of an entire directory (in this case my Downloads directory) simply use a star thusly:
stat -c "%a %n" Downloads/* 664 Downloads/localhost.sql 664 Downloads/premium-pixels-fancy-pants-blog-magazine-theme.zip 755 Downloads/premium-pixels-package 644 Downloads/readme.html 664 Downloads/RobDuck1.JPG 664 Downloads/RobDuck2.JPG 664 Downloads/socialite-modern-wordpress-theme.zip
This isn’t my ideal, however. I’d really like ls to have the option. Perhaps there’s some bastardized and recompiled ls out there. Have you ever wanted to see octal permissions on your filesystem lists? How did you go about achieving that goal?