Skip to content

Instantly share code, notes, and snippets.

@markallenpark
Created June 1, 2023 08:21
Show Gist options
  • Save markallenpark/385399a0561438cd196caaf047071fb8 to your computer and use it in GitHub Desktop.
Save markallenpark/385399a0561438cd196caaf047071fb8 to your computer and use it in GitHub Desktop.
simple script to show octal values of file permissions in a path. I didn't write this, I just have it here for easy access.
#!/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 )
}
print
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment