Display files permissions in number format i.e "0755"? [duplicate]
Is there a way to get files/directories permissions in number format "0777" instead of "-rw--r--r" format?
You can display the octal permissions for a file using the stat command:
stat -c %a [filename]
Or by using find:
find [path] -printf '%m %p\n'
Note that find is recursive, and will print all files in all subdirectories as well. You can use options like maxdepth
or prune
to stop it from recursing.
I know this is an old post but I found it while looking for a solution to this, and expanded upon it:
stat -c '%a - %n'
That will show the file permissions and the file name. This allows you to see the permissions of every file in a folder with:
stat -c '%a - %n' *
I also took this a step further and made an alias:
alias perms="stat -c '%a - %n'"
So typing perms * will give me the permissions of every file or perms file.php will give me the permissions of just that one file.
For users who find this while looking for a solution for OSX:
Versions of OSX after 10.10 no longer have a version of stat that accepts the -c parameter. If you get an error about "illegal option -- c" then you should be able to use this stat command:
stat -f "%A - %N" *
This can also be aliased like the previous command I shared:
alias perms="stat -f '%A - %N'"
You can also use this workaround:
find FILENAME/DIRECROY -printf "%m:%f\n"
Example check my Videos directory:
find Videos -printf "%m:%f\n"
755:Videos
Another Method:
Used to list all directory files with their 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}'