Cover V03, I01
Article
Listing 1
Listing 2

jan94.tar


Listing 2: Getperm script

:
#   getperm
#
#   Return octal permission number of named files
#
#   Copyright 1993, Lawrence S Reznick

if [ $# = 0 ]
then
echo "Usage:\t`basename $0` filenames"
echo "\nShows files' octal permission settings."
exit 1
fi

ls -ld $* |
awk '
{
perm = $1;
name = $9;
setting = 0;

if (toupper(substr(perm, 4, 1)) == "S") {
setting += 4000;
}
if (toupper(substr(perm, 7, 1)) == "S") {
setting += 2000;
}
if (toupper(substr(perm, 10, 1)) == "T") {
setting += 1000;
}
if (substr(perm, 2, 1) == "r") {
setting += 400;
}
if (substr(perm, 3, 1) == "w") {
setting += 200;
}
if (substr(perm, 4, 1) == "x"
|| substr(perm, 4, 1) == "s") {
setting += 100;
}
if (substr(perm, 5, 1) == "r") {
setting += 40;
}
if (substr(perm, 6, 1) == "w") {
setting += 20;
}
if (substr(perm, 7, 1) == "x"
|| substr(perm, 7, 1) == "s") {
setting += 10;
}
if (substr(perm, 8, 1) == "r") {
setting += 4;
}
if (substr(perm, 9, 1) == "w") {
setting += 2;
}
if (substr(perm, 10, 1) == "x"
|| substr(perm, 10, 1) == "t") {
setting += 1;
}
print setting, name;
}'