DEV Community

Cover image for Living in the Shell #24; chmod (Modify file/directory permissions)
Babak K. Shandiz
Babak K. Shandiz

Posted on • Originally published at babakks.github.io on

Living in the Shell #24; chmod (Modify file/directory permissions)

chmod 🔐

Modifies file/directory permissions (See here or here for more details).

Permission expressions are mostly formatted as [ugoa][+-=][rwx]:

Symbol Meaning
r Read
w Write
x Execute
Symbol Meaning
u User (owner of the file/directory)
g Group (of the file/directory)
o Other users/groups
a All users/groups

Grant all permissions to everyone; a+rwx or 777

chmod a+rwx some-file
# or
chmod 777 some-file
Enter fullscreen mode Exit fullscreen mode

Make a file executable for everyone +x

chmod +x some-file
# or
chmod a+x some-file
Enter fullscreen mode Exit fullscreen mode

Make a file executable only for the User (owner) u+x

chmod u+x some-file
Enter fullscreen mode Exit fullscreen mode

Disallow Group and Others to read/write/execute go-rwx

chmod go-rwx some-file
Enter fullscreen mode Exit fullscreen mode

Apply the same User (owner) permissions to the Group =u

chmod g=u some-file
Enter fullscreen mode Exit fullscreen mode

Rewrite permissions for the Group and Others =

chmod go=rw some-file
Enter fullscreen mode Exit fullscreen mode

Clear permissions for the Group and Others =

chmod go= some-file
Enter fullscreen mode Exit fullscreen mode

Clear all permissions =

chmod a= some-file
Enter fullscreen mode Exit fullscreen mode

About Living in the Shell

Obsessed with doing things in the shell, I’ve decided to share my daily struggles on living in the shell as terse but informative posts.

Top comments (0)