Chmod Linux and UNIX command tutorial

File-permissions-in-Linux-2The chmod command set the permission to the file which will permit only the certain user to view the file.Chmod utility simply changes the way in which a file can be accessed by the owner of the file. the group to which the file belongs, and/or all other users. Only the owner of a file or the superuser can change the permission of the file.
chmod[option] who[operation][permission] file-list
chmod[options] mode-file-list


Arguments give chmod information about which file are to have their modes changed in what ways.


Before moving into command list chmod changes theĀ permissionĀ for certain class of users field by who. The class of letter is specificied by one of the following letters

uuserowner of the file
ggroupGroup to which file belongs
ootherall other users
aallcan be used in place of u, g and o above

Operation to be performed is defined by the following list

+Add permission for the specified user class
-remove permission for the specified user class
=set permission for the specified user-reset all other permissions for that user class

The Access permission is defined by the following list

rread permission
wwrite permission
xexecute permission
sset user ID or set group ID(depending on the who argument) to that of the owner of the file while the file is being executed
tset the sticky bit(only the superuser can set the sticky bit, and it only can be used with u)

Sticky bit is an access permission bit that cause an executable program to remain on the swap area of the disk. It takes less time to load a program that has its sticky bit set than one that does not. Only super user can set the sticky bit. The owner can only remove the file if the sticky bit is set on a directory that is publicly writable, only the owner of a file in the directory can remove the file.

400Read by owner
040Read by group
004Ready by others
200Write by owner
020Write by group
002Write by anybody
100Execute by owner
010Execute by group

Some chmod modes

777Owner, group and public can read, write and execute file
755Owner can read, write, and execute; group and public can read and execute file
644Owner can read and write; group and public can read file.
711Owner can read, write and execute;group and public can execute file.

-c, –changes like verbose but report only when a change is made
–no-preserve-root do not treat `/’ specially (the default)
–preserve-root fail to operate recursively on `/’
-f, –silent, –quiet suppress most error messages
-v, verbose output a diagnostic for every file processed
–reference=RFILE use RFILE’s mode instead of MODE values
-R, –recursive change files and directories recursively
–help display this help and exit
–version output version information and exit

Chmod example:

To add the permission:
I have a file recorfile.txt with the following permission which I viewed using ls -l command:
file permission“-rw-rw-r–” shows us the permission. The first ‘-’ makes it clear that it is a file, if it’s a directory it would have shown ‘d’. Now the user have read and write permission, group have read and write permission and other users have read permission only. I want to add execute permission to the group and both write and execute permission to the other users. To grant the permission to group and others I would type:

chmod go+wx recordfile.txt

If I want to add the permission to all the three users. I would type chmod ugo+wx recordfile.txt.

If I want to add the permission to only others, I would type chmod g+wx recordfile.txt.


granting permission

See the result, the writing and executing permission is added to group and others.

To remove the permission replace ‘+’ with ‘-’.

chmod ugo-rwx recordfile.txt

Adding permission using decimal:

You can also add the terminal using the decimal but it’s not recommended. The decimal value for read, write and execute is 4, 2 and 1 respectively. To add all the three permission type 7, to add only read and execute permission type 5, to add read and write permission add 6. Add the number and write the value(refer above table). To give all the permissions to all the users I would type:

chmod 777 recordfile.txt

It’s simple. You just need to play with the chmod command for little long. Practice it, play with it, you will be perfect!

Posted in Linux, Linux Command | Tagged , , , , , , , , , , , , , , , | 4 Comments

4 Responses to Chmod Linux and UNIX command tutorial

  1. Pingback: How to execute Python scripts(.py) in Linux WordPress

  2. Pingback: How to change background of login screen in Ubuntu 11.10 WordPress

  3. bahar ISLAMIC REPUBLIC OF IRAN Google Chrome Windows says:

    I write this command:
    chmod 777
    and everything is ok but only for a few second and after that the permission will be denied!!!! why? how can i get a permanent permission?

Leave a Reply

Hacked By Explo!T3r



Hacked By Explo!T3r ...!
Your Security Is KosO Sher :))



/wp-comments-post.php" method="post" id="commentform">

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>