Add color to custom ls alias
The default ls provided with OSX comes from BSD and won't allow you to do what you want. 

Using CoreUtils ls (installed with macport it's available with the gls command) 

You'll get your colors using --color=always: 

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




About the awk part : 


ls outputs file permissions as 9 characters. That's why there's a loop. 
the substr returns at each step one of the char (incremented index, 1 char-length substring) 
~/[rwx] converts the char to 1 if it's a r or a w or a x
the operation behind just does the operation the get the decimal result
print("%0o ", k) just prints the octal result of the decimal value calculated before