consider the output of this ls -l command:
$ ls -l /usr/bin | tail
-rwxr-xr-x 1 root root 105696 Oct 25 2014 zenity
-rwxr-xr-x 1 root root 188296 Oct 21 2013 zip
-rwxr-xr-x 1 root root 86096 Oct 21 2013 zipcloak
-rwxr-xr-x 1 root root 48459 Mar 3 2015 zipdetails
-rwxr-xr-x 1 root root 2953 Oct 29 10:45 zipgrep
-rwxr-xr-x 2 root root 166584 Oct 29 10:45 zipinfo
the permissions are listed in the nice, human readable characters.
Is there a way to get ls
to output the numerical equivalent to those permissions?
ls
does not have such flag, butstat
command allows showing octal permissions. Consider sample output for a test file,stat
also has--format
flag , which allows you to "simulate"ls -l
:The only limitation here is the time format cannot be altered and color output cannot be added .
You could always alias that command in
.bashrc
to some shorter command, e.g.alias lsl2='stat --format="%a %h %U %G %s %y %n" *'
Alternatively, I've put together a small function that uses
find
andawk
for nicer formattingSample output
According to https://stackoverflow.com/questions/1795976/can-the-unix-list-command-ls-output-numerical-chmod-permissions it is not possible.
An answer to that question, however proposes a way to 'almost' achieve that:
You could make that an alias for easy use - but ls alone can not do this.
Here's a fun pipeline
printf "%04d\n" $(stat -c '%a' *)
-- prints the zero-padded octal access rights for each filels -l | sed 1d
-- the long listing, minus the first line "total 12345"paste <(...) <(...)
-- takes one line from each process substitution, and joins them with a tabsed -r 's/([[:digit:]]+)\t(.)........./\2\1/'
-- replaces therwxrwxrwx
human readable permissions with the octal value.Take a look at GNU find:
See:
man find
Hmm... found this is in searching for something totally else,
One more to the collection: