How can I automatically (!) deternine the numerical permission value of a file? With a single command (I dont know any, didnt find it anywhere) or with a small script.
command "file" -> output "755" or so....
you will have to define the term "small" in reference to a script. it should take at least ten lines but i have not thought much about the problem.
i suggest using several cut commands to put the various parts (rwx or what have you) into some variables then do a simple string check. if you want to get fancy you can use perl, but ksh works fine. either that or get used to interpreting them visually, i don't know of a prog that does this for you.
Yes certainly I started to do some perl ;-)..
but I was looking in parallel for one of those famous undocumented commands, you wont find in the manuals...
This one came out bigger then 10 lines ...:
================================
#!/bin/ksh
#Usage : check <filename>
#Displays the numeric permission value for files and directories
set –A INC 4 2 1 4 2 1 4 2 1
integer I=0 #counter for the array
integer count=0 #counter for the owner/group/other position
integer sum=0 #sums the digit
for BYTE in 2 3 4 5 6 7 8 9 10 ;do
if [[ `ls –ld $1|awk '{ print $1 }'|cut –c $BYTE` != "-" ]] ;then
sum=$sum+${INC}
fi
I=$I+1
count=$count+1
if (( $count == 3 )) ;then
echo “$sum\c”
sum=0
count=0
fi
done
echo “”
================================
Yes, thanks a lot! Meanwhile I wrote my Perl script and it works even with the t and s-bits, but I didnt know the stat or any octal commands so I build a rather lengthy workaround for it...The last idea by ogniemi is extremely nice, now I found the same idea in the Camel book of Perl.
Thx to you all!
(PS: our task was to rebuild all permissions in the /etc fs
and along all links in it on a 4.3.3 machine. User made a su - root, tried to make a "chmod -R 644 $path/etc/*" but his variable $path was empty! As /etc/ is linked to /usr/sbin nearly every system command wasnt executable anymore...)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.