CyberTek - the future at the present!
Google

Display octal permissions

Posted by: admin (Oct 25)

When we use the ls command to view the permissions of files in the following format:

-rw-r-r-1 user group 49296 Mar 24 2006 file.bin

As have the need to display octal permissions of the file that the script:

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

The command displays the permissions octal style + drwxr-xr-x.

If you satisfy the result you can make permanent and easier to use by creating an alias in the shell you used to like and parameter. For bash you have to edit your home directory in the file ~ /. Bashrc, after logout and login you can use the 'l' alternative to the classic comanto 'ls':

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

Result:

600-rw --- 1 user group 134K Apr 21 2006 mbox

Published in: linux, shell, tips

Add A Comment

Powered by CyberTek - Remote Assistance