/ 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.
Expand |
Embed | Plain Text
#!/bin/sh ls -l | awk '{ k = 0 s = 0 for( i = 0; i <= 8; i++ ) { k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) ) } j = 4 for( i = 4; i <= 10; i += 3 ) { s += ( ( substr( $1, i, 1 ) ~ /[stST]/ ) * j ) j/=2 } if ( k ) { printf( "%0o%0o ", s, k ) } }'
You need to login to post a comment.
