User Tools

Site Tools


linux:shell_commands:chmod_nummeric

Display numeric permissions using ls

Create an alias for the LS command.

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) *2^(8-i));if(k)printf("%0o ",k);print}'

Output should be with the nummeric permissions at the beginning of each row:

adm@lxpssl:/home$ ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) *2^(8-i));if(k)printf("%0o ",k);print}'
total 3
755 drwxr-xr-x 2 adm        domain users 1024 Mar 22  2016 adm
755 drwxr-xr-x 2 adm1       domain users 1024 Feb 11  2016 adm1
755 drwxr-xr-x 2 adm2       domain users 1024 Apr 11  2016 adm2
adm@lxpssl:/home$
linux/shell_commands/chmod_nummeric.txt · Last modified: 2017/08/10 11:00 (external edit)