Operating System - HP-UX
1827824 Members
2023 Online
109969 Solutions
New Discussion

Re: Any commands or script can reverse the permission?

 
SOLVED
Go to solution
KennyC
Advisor

Any commands or script can reverse the permission?

Hi Experts,

I would like to know any commands or script can return the reverse value of the permission of the file or directory. ie, if the file had -rwxr-x---, it will return 750, -rwsr-x--- will return 4750 (Return sticky bit also)

Thanks in advance.
KennyC.
3 REPLIES 3
Dietmar Konermann
Honored Contributor
Solution

Re: Any commands or script can reverse the permission?

You may compile this little source:

#include
#include

int main (argc, argv)
int argc;
char ** argv;
{
struct stat buf;

if (stat(argv[1], &buf) != 0) {
perror ("stat failed");
exit (1);
}

printf ("%04o\n", buf.st_mode & 07777);
exit (0);
}


e.g.
save it as perm.c, then compile it using

# cc -o perm perm.c

# ./perm /etc/passwd
0444


Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
H.Merijn Brand (procura
Honored Contributor

Re: Any commands or script can reverse the permission?

a5:/tmp 108 > ls -l xx
-rwxr-xr-- 1 merijn softwr 0 Mar 13 09:40 xx
a5:/tmp 109 > perl -le'print+(stat)[2]for@ARGV' xx
33260
a5:/tmp 110 > perl -le'printf"0%o\n",(stat)[2]for@ARGV' xx
0100754
a5:/tmp 111 >


Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
KennyC
Advisor

Re: Any commands or script can reverse the permission?

Thanks for your help. It save me alot of times.

Thanks very much.
KennyC.