21

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?

30

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

4
stat FILE_OR_FOLDER_PATH

this is quicker but displays the whole lot

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.