Navigate back to the homepage

Linux chmod Command

Nancy Chauhan
November 4th, 2018 · 1 min read

chmod

chmod is used to change the permissions of files or directories. On Linux and other Unix-like operating systems, there is a set of rules for each file which defines who can access that file, and how they can access it. These rules are called file permissions or file modes. The command name chmod stands for “change mode”, and it is used to define the way a file can be accessed. In general, chmod commands take the form: chmod options permissions file name

Let’s say you are the owner of a file named myfile, and you want to set its permissions so that:

11) the user can read, write, ande xecute it;
22) members of your group can read ande xecute it; and
33) others may only read it.

This command will do the trick: chmod u=rwx,g=rx,o=r myfile

This example uses symbolic permissions notation. The letters u, g, and o stand for “user”, “group”, and “other”. The equals sign (”=”) means “set the permissions exactly like this,” and the letters “r”, “w”, and “x” stand for “read”, “write”, and “execute”, respectively. The commas separate the different classes of permissions, and there are no spaces in between them.

Here is the equivalent command using octal permissions notation:

chmod 754 myfile

Here the digits 7, 5, and 4 each individually represent the permissions for the user, group, and others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0:

14 stands for "read",
22 stands for "write",
31 stands for "execute", and
40 stands for "no permission."

More articles from Nancy Chauhan

Lift As You Climb

“And so, lifting as we climb, onward and upward we go, struggling and striving, and hoping that the buds and blossoms of our desires will burst into glorious fruition ere long.”

October 17th, 2018 · 2 min read

Faster Builds with Docker Caching

Faster Builds with Docker caching

May 20th, 2020 · 1 min read
© 2018–2020 Nancy Chauhan
Link to $https://twitter.com/_nancychauhanLink to $https://github.com/Nancy-ChauhanLink to $https://www.linkedin.com/in/nancy-chauhan/Link to $https://www.instagram.com/_nancychauhan/Link to $https://medium.com/@_nancychauhan