Posted By

mladoux on 06/12/11


Tagged

system administration utility admin


Versions (?)

ls octal chmod out


 / Published in: Awk
 

Simple script to output chmod permissions in octal. Good for learning environments, and security troubleshooting. I didn't write this one, I picked up from a friend and he didn't write it either.

  1. #!/bin/sh
  2.  
  3. ls -l | awk '{
  4. k = 0
  5. s = 0
  6. for( i = 0; i <= 8; i++ )
  7. {
  8. k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) )
  9. }
  10. j = 4
  11. for( i = 4; i <= 10; i += 3 )
  12. {
  13. s += ( ( substr( $1, i, 1 ) ~ /[stST]/ ) * j )
  14. j/=2
  15. }
  16. if ( k )
  17. {
  18. printf( "%0o%0o ", s, k )
  19. }
  20. print
  21. }'

Report this snippet  

You need to login to post a comment.