"755"-style permissions with 'ls'

After a quick Google search for "ls permissions octal" I found a very handy alias to put in my .bashrc. Not only is it handy to see the OCTAL value of the permissions for each file/dir, it will undoubtedly help you more quickly recognize/interpret the normal ls -al output.

alias lso="ls -alG | 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}'"

#example usage:
mycomp:~ adam$ lso
 755 drwxr-xr-x   15 adam  staff    510 Dec  6 02:47 .vim
 644 -rw-r--r--    1 adam  staff   1136 Dec 18 16:55 .vim_mru_files
 600 -rw-------    1 adam  staff  13665 Dec 18 16:56 .viminfo
You can also type (or paste) this slightly different version into terminal:
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}'

Tags: 

Add new comment