Created: 2023-04-20 15:46
Status: #concept
Subject: Programming System Administration
Tags: Bash Shebang Linux
chmod
Stands for "Change Mode" and allows us to edit read, write, execute bits of a file.
- It's in the format:
- --- --- ---
, which corresponds to the File Type, User Permissions, Group Permissions, and Other/Global Permissions. - The permissions are
rwx
.
Permission | Description | Octal | Decimal |
---|---|---|---|
--- |
No Permission | 000 | 0 (0+0+0) |
--x |
Execute | 001 | 1 (0+0+1) |
-w- |
Write | 010 | 2 (0+2+0) |
-wx |
Execute & Write | 011 | 3 (0+2+1) |
r-- |
Read | 100 | 4 (4+0+0) |
r-x |
Read & Execute | 101 | 5 (4+0+1) |
rw- |
Read & Write | 110 | 6 (4+2+0) |
rwx |
Read, Write & Execute | 111 | 7 (4+2+1) |
Examples
# these are all equivalent - enables all permissions of a file for all users
$ chmod 777 example.txt
$ chmod u=rwx,g=rwx,o=rwx example.txt
$ chmod a=rwx example.txt
# makes a file executable
$ chmod u+x ~/example.py # for the current user
$ chmod a+x ~/example.py # for all users, a is equivalent to ugo
# removes execution permissions for everyone
$ chmod a-x chmodExampleFile.txt