UNIX permissions explained

So what does "sudo chmod -R 777 /dir" mean?

UNIX permissions explained
Photo by Lukas / Unsplash

So what does "sudo chmod -R 777 /dir" mean?

N Description ls Binary
0 No permission at all --- 000
1 Execute only -x 001
2 Write onl -w- 010
3 Write and execute -wx 011
4 Read only r- 100
5 Read and execute r-x 101
6 Read and write rw- 110
7 Read, write and execute rwx 111

Given the table above - r = read, w = write and x = execute.

sudo – Originally “superuser do”, is a command in UNIX-like machines that allows the user to run programs with (by default) superuser privileges.

chmod – Or “change mode” is a UNIX command that allows the user to change access permissions to files and/or directories.

-R – The command flag to make the operation recursive, or simply put, apply all changes in the directory and its children.

1st Number (7) – Represents the User. 7 means to give the user rwx privilege.

2nd Number (7) – Represents the Group. 7 means to give the group rwx privilege.

3rd Number (7) – Represents Other. 7 means to give “other” rwx privilege. An example of “other” are web browsers. Web browsers won’t have the access to your website if you give -wx privilege to your web server directory.

Many web servers use 755 for directories and 644 for files.

Now you’re ready to mess up with your files.