Skip to content

Instantly share code, notes, and snippets.

@chrislovecnm
Created June 27, 2014 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislovecnm/5aa6ac7a4828b5a92d03 to your computer and use it in GitHub Desktop.
Save chrislovecnm/5aa6ac7a4828b5a92d03 to your computer and use it in GitHub Desktop.
get chmod numbers for a directory
#!/bin/bash
// get the chmod numbers for a directory
// http://stackoverflow.com/questions/1795976/can-the-unix-list-command-ls-output-numerical-chmod-permissions/1796009
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}'
@chrislovecnm
Copy link
Author

Brilliant!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment