M BUZZ CRAZE NEWS
// general

How to get chmod (octal) permissions of the folder in the terminal?

By Emma Johnson

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?

3 Answers

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

1
stat FILE_OR_FOLDER_PATH

this is quicker but displays the whole lot

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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