How to get chmod (octal) permissions of the folder in the terminal?
I can look in properties of this folder but I want to get properties fast and in digits (octal, e.g. 755
, etc.)
What am I to type in terminal to know the chmod of the file or folder I want?
Solution 1:
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
Solution 2:
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