trapd00r / ls--

ls on steroids
505 stars 45 forks source link

[ WISH ] Show file permissions in octal format #45

Open cig0 opened 9 years ago

cig0 commented 9 years ago

Hello all, Longtime ls++ fan here. If you guys ever have the time I think it would be cool to add octal capabilities to the ls listing like I use with the traditional GNU ls:

...
 664 -rw-rw-r--. 1 msx msx 117K May 25 12:16 Screenshot from 2015-05-25 12:15:58.png
 777 lrwxrwxrwx. 1 msx msx   31 Apr 10 20:32 Soulseek Chat Logs -> /home/@data/Soulseek Chat Logs//
 777 lrwxrwxrwx. 1 msx msx   17 Mar 24 23:42 Stash -> /home/@data/Stash/
 777 lrwxrwxrwx. 1 msx msx   21 Feb 16 14:31 Templates -> /home/@data/Templates/
 664 -rw-rw-r--. 1 msx msx  52K May 18 18:33 TIGO_MFS_Manual Tecnico_v1.odt
 640 -rw-r-----. 1 msx msx  13K May 22 18:22 TIGO.png
 777 lrwxrwxrwx. 1 msx msx   18 Feb 16 14:31 Videos -> /home/@data/Videos/
 664 -rw-rw-r--. 1 msx msx  484 May  5 20:56 VM_GH
 777 lrwxrwxrwx. 1 msx msx   15 Feb 16 14:31 VMs -> /home/@data/VMs/
 640 -rw-r-----. 1 msx msx 988K May  4 00:30 yunrl7fmeiespkovaghp.jpg

To achieve this, I use this beautiful awk command - kudos to its creator:

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}'

Like:

/usr/bin/ls -lha --group-directories-first --color -F | 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}'

Cheers