Created
June 10, 2019 00:34
-
-
Save mladoux/e4bd954e97b95281519ad2e09393f4e3 to your computer and use it in GitHub Desktop.
Simple awk script to convert permissions to octal ( good for learning octal permissions )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ) | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment