How to get chmod (octal) permissions of the folder in the terminal?
What am i to type in terminal to know the chmod of the folder i want?
stat -c %a FILE_OR_FOLDER_PATH
e.g. stat -c %a /etc
shows 755
GNU find
Makes use of %m
format for -printf
flag.
$ find /etc/ -maxdepth 0 -printf "%m\n"
755
or
$ find /etc/ -prune -printf "%m\n"
755
Python
$ python -c 'import os,sys;print(oct(os.stat(sys.argv[1]).st_mode))' /etc
040755
Or if we want to only get the owner-group-other permission bits only:
$ python -c 'import os,sys;print(oct(os.stat(sys.argv[1]).st_mode)[-3:])' /etc
755
Perl
Via File::stat
, pretty much same as in the documentation:
$ perl -le 'use File::stat; $fs=stat($ARGV[0]);printf "%o\t%s\n",$fs->mode & 07777,$ARGV[0]' /etc
755 /etc
stat FILE_OR_FOLDER_PATH
this is quicker but displays the whole lot