ls with octal permissions: single line solution

  • Follow


Hi there,

For those who want to have "0755" style permissions with ls I made this
script:

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

Just type the line above to get the full ls listing with octal + the
drwxr-xr-x style.

If you want to make it permanent, just paste this line into ~/.bashrc
file (and use "l" insted of ls):

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

Cheers,
Mr. Milk

0
Reply internetwalker (1) 9/17/2006 7:11:21 AM


0 Replies
759 Views

(page loaded in 0.059 seconds)

Similiar Articles:













7/23/2012 7:00:21 AM


Reply: