IBM Support

IBM AIX: How to show numerical permissions

How To


Summary

On AIX, the numerical permissions of a file or directory can be specified with the 'chmod' command to set its permissions. However, there is not a command to show the numerical permissions, similar to the 'stat' command on Linux.
So it is needed to compose a script ‘stat’ to show numerical permissions on AIX (try to match the functionality of Linux stat).

Objective

When running the 'stat' command against a file or directory, its numerical permissions will be shown. Such as:
# stat /usr/bin/chuser
4550 -r-sr-x---    1 root     security     136910 Apr 16 05:57 /usr/bin/chuser

Steps

1. Compose a script file named /usr/bin/stat:

# vi /usr/bin/stat
(input the following lines)
#!/usr/bin/ksh
/usr/bin/ls -l $@ | /usr/bin/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;}"
(save and quit from vi)
2. Add the execution bits to the stat file:
# chmod a+x /usr/bin/stat
# ls -l /usr/bin/stat
-rwxr-xr-x    1 root     system          232 Jul 04 10:02 /usr/bin/stat
Now the 'stat' command can be executed to show the numerical permissions of files.
For example:
# stat /usr/bin/chuser
4550 -r-sr-x---    1 root     security     136910 Apr 16 05:57 /usr/bin/chuser
# stat -d /tmp
1777 drwxrwxrwt   11 bin      bin            4096 Jul 04 16:50 /tmp

Additional Information

Furthermore, this 'stat' command can be specified within the 'find' command to show the files' numerical permissions. For example:
# find /usr/bin -perm -4000 -exec stat {} \;
6550 -r-sr-s---    1 root     adm          208098 Jun 02 2015  /usr/bin/acctctl
6550 -r-sr-s---    1 root     adm           26847 Jun 02 2015  /usr/bin/acctras
6555 -r-sr-sr-x    1 root     cron          64514 Apr 16 05:57 /usr/bin/at
<...snip...>

Document Location

Worldwide

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG10","label":"AIX"},"Component":"","Platform":[{"code":"PF002","label":"AIX"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
09 March 2020

UID

ibm10958285