Skip to content

Instantly share code, notes, and snippets.

@juanarbol
Last active September 25, 2024 18:24
Show Gist options
  • Save juanarbol/c44e736be70279c1fd5d68aa24f9d8be to your computer and use it in GitHub Desktop.
Save juanarbol/c44e736be70279c1fd5d68aa24f9d8be to your computer and use it in GitHub Desktop.
Chmod cheat sheet

Chmod codes cheat sheet

How to use chmod codes in UNIX:

  1. There are three types of permissions in files and folders in unix
    1. Read (r)
    2. Write (w)
    3. Execute (x)
  2. And, there is a classification of users called UGO (explained bellow):
    1. U ~> User (usually, you)
    2. G ~> Group (eg sudo group)
    3. O ~> Others

When you run $ ls -l your output will be something like this:

-rwxrwxrwx@  1 user  staff  708301983 Aug 11 13:51 all.zip
-rw-r--r--   1 user  staff          0 Aug 22 22:10 chmodCheatSheet.md
-r--------@  1 user  admin       1692 Jul  6 10:13 deploykey.pem
drwxr-xr-x   3 user  staff        102 Aug 20 19:14 deploynode

How to read this?

Where is a letter put a 1 and where is a - put a 0. Examples:

U G O
r w x r w x r w x
1 1 1 1 1 1 1 1 1

So, user, group and others can read, write and excute the file or folder

U G O
r w - r -- r - x
1 1 0 1 0 0 1 0 1

So, user can read and write, group can only read, finally other can read and execute

As you can see, we can play with these permissions

U G O
r - x r w - - - -
1 0 1 1 1 0 0 0 0
U G O
- w x r - x - - x
0 1 1 1 0 1 0 0 1

Finally, the codes! (sorry)

Bin Decimal Representation
000 0 - - -
001 1 - - x
010 2 - w -
011 3 - w x
100 4 r - -
101 5 r - x
110 6 r w -
111 7 r w x

The syntax is something like this: $ chmod u/permissions g/permissions o/permissions file[or /dir/]

  • So, if I run $ chmod 777 file <=> rwx rwx rwx everybody can do anything with file
  • Or I run $ chmod 744 dir <=> rwx r-- r--only user can read, write and execute, group and others only read dir.
  • Or run $ chmod 200 file2 <=> -w- --- ---only you can write file2

Thanks for reading, I hope it works! Follow me on Twita and GitHub

Refs:

  1. http://www.pa.msu.edu/~abdo/unixcc.html
  2. http://www.yourownlinux.com/2013/09/chmod-basics-of-filesdirectories.html

Special thanks:

@gabekz
Copy link

gabekz commented Nov 18, 2020

I made some changes in my fork for spelling errors.
https://gist.github.com/GabeKutuzov/ec788f2d8456fadf7754a61a6a5ed9b0

Thank you for this gist

@juanarbol
Copy link
Author

I made some changes in my fork for spelling errors.
https://gist.github.com/GabeKutuzov/ec788f2d8456fadf7754a61a6a5ed9b0

Thank you for this gist

Thank you Gabe! I've updated the gist and added you to the credits. :)

@gabekz
Copy link

gabekz commented Dec 21, 2020

I made some changes in my fork for spelling errors.
https://gist.github.com/GabeKutuzov/ec788f2d8456fadf7754a61a6a5ed9b0
Thank you for this gist

Thank you Gabe! I've updated the gist and added you to the credits. :)

Awesome! Just saw. Thank you.

@wtfc0d3
Copy link

wtfc0d3 commented Jun 25, 2021

1 execute
2 write
4 read

1+2+4=7: execute, write and read
1+4=5: execute + read
2+4=6: write and read

@desr3333
Copy link

thanks a lot, you saved my day.

@mttaborturtle
Copy link

Thank you for putting this up! I'm always coming back to the classics!

@szabikr
Copy link

szabikr commented Nov 15, 2021

Great explanation, thank you!

I also like the one where you have to specify the letters for example to make a file executable for user, $ chmod u+x {file-name} command can be used.

@inezabonte
Copy link

Thank you

Copy link

ghost commented Jan 11, 2022

I've made a few grammatical changes for ease of understanding and corrected a few spelling errors in my fork of this gist.
https://gist.github.com/Saharsh0028/4dba3f6b489936fd465f871458cdbf0d

Thank you for this gist @juanarbol

@psrvere
Copy link

psrvere commented Aug 22, 2024

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment