Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. More ways to get the info! - we shoot all of our new original content out as well as random messages on Twitter and our newsletter!. Twitter | Newsletter
    Dismiss Notice

command: chmod

Discussion in 'Linux Beginner Tutorials' started by Rob, Nov 4, 2011.

  1. Rob

    Rob Administrator
    Staff Member

    Oct 27, 2011
    Likes Received:
    chmod is a Linux command that will let you "set permissions" (aka, assign who can read/write/execute) on a file.

     chmod permissions file 
     chmod permission1_permission2_permission3 file 
    When using chmod, you need to be aware that there are three types of Linux users that you are setting permissions for. Therefore, when setting permissions, you are assigning them for "yourself", "your group" and "everyone else" in the world. These users are technically know as:

    Therefore, when setting permissions on a file, you will want to assign all three levels of permissions, and not just one user.

    Think of the chmod command actually having the following syntax...
    Now that you understand that you are setting permissions for THREE user levels, you just have to wrap your head around what permissions you are able to set!

    There are three types of permissions that Linux allows for each file.

    (Log in to hide this advertisement)

    Putting it all together:
    So, in laymen terms, if you wanted a file to be readable by everyone, and writable by only you, you would write the chmod command with the following structure.
    Wait! What are those numbers?!?
    Computers like numbers, not words. Sorry. You will have to deal with it. Take a look at the following output of `ls -l`
    [[email protected]]$ ls -l 
    -rw-r--r-- 1 gcawood iqnection 382 Dec 19 6:49 myDoc.txt 
    You will need to convert the word read or write or execute into the numeric equivalent (octal) based on the table below.

    Practical Examples

    Wait! I don't get it... there aren't enough permissions to do what I want!
    Good call. You need to add up the numbers to get other types of permissions...

    So, try wrapping your head around this!!
    7 = 4+2+1 (read/write/execute)
    6 = 4+2 (read/write)
    5 = 4+1 (read/execute)
    4 = 4 (read)
    3 = 2+1 (write/execute)
    2 = 2 (write)
    1 = 1 (execute)

    Good luck! Hope this helps.
    (ps, never set things to 777 unless you have a really good reason to do so.)
    Ankit Patel, ROY, Milan and 9 others like this.
  2. AlienGod

    AlienGod New Member

    Sep 13, 2017
    Likes Received:
    I'm falling in love with this... Gratitude
    DanB and Rob like this.
  3. StarBaseONE2

    StarBaseONE2 New Member

    Jan 2, 2018
    Likes Received:
    This one took me a while to understand well enough to be able to use without having to 'argue' with my machine to achieve the results I desired. LOL

    Rob this was a good way of presenting the concept.
    wizardfromoz likes this.

Share This Page