≡ Menu

7 Chmod Command Examples for Beginners

Earlier we discussed about how to use octal permission bits with chmod. In this article, let us review how to use symbolic representation with chmod.

Following are the symbolic representation of three different roles:

  • u is for user,
  • g is for group,
  • and o is for others.

Following are the symbolic representation of three different permissions:

  • r is for read permission,
  • w is for write permission,
  • x is for execute permission.

Following are few examples on how to use the symbolic representation on chmod.

1. Add single permission to a file/directory

Changing permission to a single set. + symbol means adding permission. For example, do the following to give execute permission for the user irrespective of anything else:

$ chmod u+x filename

2. Add multiple permission to a file/directory

Use comma to separate the multiple permission sets as shown below.

$ chmod u+r,g+x filename

3. Remove permission from a file/directory

Following example removes read and write permission for the user.

$ chmod u-rx filename

4. Change permission for all roles on a file/directory

Following example assigns execute privilege to user, group and others (basically anybody can execute this file).

$ chmod a+x filename

5. Make permission for a file same as another file (using reference)

If you want to change a file permission same as another file, use the reference option as shown below. In this example, file2’s permission will be set exactly same as file1’s permission.

$ chmod --reference=file1 file2

6. Apply the permission to all the files under a directory recursively

Use option -R to change the permission recursively as shown below.

$ chmod -R 755 directory-name/

7. Change execute permission only on the directories (files are not affected)

On a particular directory if you have multiple sub-directories and files, the following command will assign execute permission only to all the sub-directories in the current directory (not the files in the current directory).

$ chmod u+X *

Note: If the files has execute permission already for either the group or others, the above command will assign the execute permission to the user

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Egor June 8, 2010, 3:32 am

    I think correct command for the p.3 in accordance with its subject should be
    $ chmod u-rw filename, don’t I?

  • nardi June 8, 2010, 5:59 am

    The last one is most handy! Can’t even remember, how many times I tried to remove exec permision from files copyed from M$ systems but not affect directories.
    former solution:
    for f in `ls -R` ; do [ ! -d “$f” ] && chmod a-x “$f” ; done
    and now:
    chmod -R a-x,u+X *

    big thx

  • rbz June 8, 2010, 7:20 am

    While the first six examples are rather trivial I agree for the last one. I’ve been looking for this solution for months.

    chmod -R a-x,u+X * – such a beauty!


  • Alex June 12, 2010, 12:51 am

    The last one is truly great. I’ve always used “find -type d -exec …” for this. I’m a little confused about your note, though. Why would it care about the group permissions?

  • nardi June 13, 2010, 1:26 pm

    The note is about regular files, that the +X rule is not only affecting directories. See man chmod or try it yourself by hand.

    This will set the exec rights:
    nardi@kub1x ~/test $ ll file
    -rw-r-xr– 1 nardi nardi 56 Jun 13 21:06 file*
    nardi@kub1x ~/test $ chmod a+X file
    nardi@kub1x ~/test $ ll file
    -rwxr-xr-x 1 nardi nardi 56 Jun 13 21:06 file*

    This won’t set anything, because regular file “file” is neither a directory nor has any exec bit on.
    nardi@kub1x ~/test $ ll file
    -rw-r–r– 1 nardi nardi 56 Jun 13 21:06 file
    nardi@kub1x ~/test $ chmod u+X file
    nardi@kub1x ~/test $ ll file
    -rw-r–r– 1 nardi nardi 56 Jun 13 21:06 file

  • john August 30, 2011, 7:32 am

    chmod -R a-x,u+X *

    this command applyed my vstfd stop please give solution

  • Claudia February 22, 2012, 5:11 am

    I used to work with linux command in the University and after a pause of few years… it brought me back to ‘beginers mode’ when I needed to use chmod.

    I was looking for some sites where I can find a comprehensive explanation with few examples. I could benefit a lot from this guide and a BIG “THANK YOU”!

  • prabhakar March 24, 2012, 12:18 pm

    thanks for posting chmod command information

  • Hal February 15, 2013, 2:12 am

    Hey! Thanks for the examples,

    I have read thousand article about chmod. Everybody writes what chmod does and Which file permission what does..Cool! But,

    Noone writes where I have to set those codes…To be able to change file permission exp:
    I will use this $ chmod u+r,g+x filename.

    Where do I have to add this?

    Thanks alot!

  • Rohit July 19, 2013, 3:44 am

    What about “STICKY BITS” ??

  • jose August 13, 2013, 8:51 am

    how to fix this? the terminal says ‘no such file is in the directory’.

  • ram August 19, 2013, 8:29 am

    i was changing file permission of a certain file named “hostname” with a file attribute of r-x r-x rx. I went to that file location since it was located in a folder directory of /bin. when I use the chmod it says “no file name” but I am already inside /bin where hostname is located. any help please!

  • julijuli October 29, 2013, 9:42 am

    thats good

  • Varun Jain December 4, 2013, 10:11 pm

    The beauty of Linux file security is chmod. It allow all user to different permission.
    Read: 4
    Write: 2
    Execute: 1
    First character for : User
    Second for : Group
    and Third for : All
    For example User wants to only read file only for user then:
    chmod 400
    easy job!!
    Love File Permission

  • Mitch December 23, 2013, 12:15 pm

    Yes, simple binary. RWX 4,2,1. Any combination for owner, group, all. Here are some very common chmod examples.
    755 – Can’t execute without read. So owner gets all rights and all others can execute and read.
    644 – Non-executable file that the owner can write to and all others can read.
    666 Read/Write by all, inherently evil.

  • Karthik Srigaddhe March 20, 2014, 12:55 am

    Thank u so much for this info…

    I find it very useful for beginners

  • Paul Johnson April 29, 2014, 9:38 am

    Shouldn’t example 3 be “$ chmod u-rw filename” instead of “$ chmod u-rx filename”?

  • Terry Clancy July 10, 2014, 10:26 pm

    Hi SathiyaMoorthy

    I am trying to use ncftp to use chmod to set permssions on files and folders on a site I have hosted on a Windows Server at GoDaddy

    I connect OK but when I enter

    chmod a+rwx web.cofig

    I get this error

    chmod web.config: server said: ‘SITE’: command not understood.

    Any idea what the problem is ?


    Terry Clancy

  • Minol October 18, 2014, 12:05 pm

    chmod sticky mod How?

  • Baju koko January 30, 2015, 6:33 am

    how to chmod a+rx ?

  • vishal February 8, 2015, 3:59 am

    great help
    But can you please explain 3rd example
    I think it should be
    chmod u – rw filename.

  • semaj February 10, 2015, 8:06 pm

    I new to AIX, I want to change 800 files system permissions to 750, and the owner:group. How can I do this in a script, all at once?

  • Javad Sadeqzadeh April 18, 2015, 8:32 am

    This is one of the greatest and most clear guides on permissions and the chmod command. Thank you for such a clear guide.

  • Kelum August 20, 2015, 1:01 am

    Thank u so much for this info…
    I find it very useful for beginners

  • ramesh June 22, 2016, 2:40 am

    iam read and observe above all commands but one of the command is wrong in my guess. the no.3. is asking remove read and write but the example explain in command is “u-rx” thhis command using remove in read and execution permission not for remove in write permission and this is also working in permission for write only.so the 3 no command is wrong.

    3. Remove permission from a file/directory

    Following example removes read and write permission for the user.

    $ chmod u-rx filename

  • charles January 13, 2017, 1:42 am

    its very useful for beginners.