Skip to content

Instantly share code, notes, and snippets.

@mladoux
Created December 25, 2018 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mladoux/eb7d53c02359de97e0c7bb513ebc94e3 to your computer and use it in GitHub Desktop.
Save mladoux/eb7d53c02359de97e0c7bb513ebc94e3 to your computer and use it in GitHub Desktop.
Get octal output from ls using awk
#!/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