is there ls -l numeric formating?

ls does not have such flag, but stat command allows showing octal permissions. Consider sample output for a test file,

testdir:$ stat TESTER
  File: ‘TESTER’
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 801h/2049d  Inode: 1197        Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ xieerqi)   Gid: ( 1000/ xieerqi)
Access: 2015-11-05 17:42:01.914917433 -0700
Modify: 2015-11-05 17:42:01.914917433 -0700
Change: 2015-11-05 18:41:04.463776180 -0700
 Birth: -

stat also has --format flag , which allows you to "simulate" ls -l :

testdir:$ stat --format="%a %h %U %G %s %y %n" * | head -n 3                   
664 1 xieerqi xieerqi 0 2015-11-05 17:42:01.918917452 -0700 Aaaaaaa.bbb - 0000003 tag tag_tag 9tag
664 1 xieerqi xieerqi 0 2015-11-05 17:42:01.922917471 -0700 Aaaaaaa.bbb - 0000004 tag tag_tag 9tag
664 1 xieerqi xieerqi 0 2015-11-05 17:42:01.930917509 -0700 Aaaaaaa.bbb - 0000005 tag tag_tag 9tag

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 and awk for nicer formatting

 function lsl2
   {
     find . -maxdepth 1 | sort |  xargs -I{} stat --format="%a %h %U %G %s %y %n" {}  | awk '{$7=substr($7,1,5);$8    =" ";print}'
  }

Sample output

testdir:$ lsl2 | head -n 7
775 3 xieerqi xieerqi 4096 2015-11-05 22:20   .
664 1 xieerqi xieerqi 0 2015-11-05 17:42   ./Aaaaaaa.bbb - 0000003 tag tag_tag 9tag
664 1 xieerqi xieerqi 0 2015-11-05 17:42   ./Aaaaaaa.bbb - 0000004 tag tag_tag 9tag
664 1 xieerqi xieerqi 0 2015-11-05 17:42   ./Aaaaaaa.bbb - 0000005 tag tag_tag 9tag
664 1 xieerqi xieerqi 0 2015-11-05 17:42   ./Aaaaaaa.bbb - 0000006 tag 9tag
664 1 xieerqi xieerqi 0 2015-11-05 17:42   ./Aaaaaaa.bbb - 0000006 tag tag_tag 9tag
664 1 xieerqi xieerqi 0 2015-11-05 17:42   ./Aaaaaaa.bbb - 0000007 tag 9tag

testdir:$ type lsl2
lsl2 is a function

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:

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
         *2^(8-i));if(k)printf("%0o ",k);print}'

You could make that an alias for easy use - but ls alone can not do this.


Here's a fun pipeline

paste <(printf "%04d\n" $(stat -c '%a' *)) <(ls -l | sed 1d) | 
  sed -r 's/([[:digit:]]+)\t(.)........./\2\1/' 
  • printf "%04d\n" $(stat -c '%a' *) -- prints the zero-padded octal access rights for each file
  • ls -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 tab
  • sed -r 's/([[:digit:]]+)\t(.)........./\2\1/' -- replaces the rwxrwxrwx human readable permissions with the octal value.