I wanted to see the chmod numbers for the files in a directory. So I can copy them to the other files. Since I don’t want to do that dumb chmod math, I looked for a way to do it easily.

I found the following code:


Add the following to your .bashrc (or .zshrc file if you are cool) and then reload the source of your terminal.

function show-permissions() {
  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}'


644 -rw-r--r--   1 james2doyle   README.md
644 -rw-r--r--   1 james2doyle   LICENSE

greping the output

show-permissions | grep README.md
644 -rw-r--r--   1 james2doyle   README.md

Here is the stackoverflow question where I stole this from.