Member Sign In
Not a member?

A Wired.com user account lets you create, edit and comment on Webmonkey articles. You will also be able to contribute to the Wired How-To Wiki and comment on news stories at Wired.com.


It's fast and free.

Webmonkey is a property of Wired Digital.
processing...
Join Webmonkey

Please send me occasional e-mail updates about new features and special offers from Wired/Webmonkey.
Yes No

Please send occasional e-mail offers from Wired/Webmonkey affiliated web sites and publications, and carefully selected companies.
Yes No

I understand and agree that registration on or use of this site constitutes agreement to Webmonkey's User Agreement and Privacy Policy.
Webmonkey is a property of Wired Digital.
processing...

Retrieve Sign In

Please enter your e-mail address or username below. Your username and password will be sent to the e-mail address you provided us.

or
Webmonkey is a property of Wired Digital.
processing...

Welcome to Webmonkey

A private profile page has been created for you.
As a member of Webmonkey, you can now:
  • edit articles
  • add to the code library
  • design and write a tutorial
  • comment on any Webmonkey article
Close
Webmonkey is a property of Wired Digital.

Sign In Information Sent

An e-mail has been sent to the e-mail address registered in this account.
If you cannot find it in your in-box, please check your bulk or junk folders.
Sign In
Webmonkey is a property of Wired Digital.

Chmod

/skill level/
/viewed/
0 Times


chmod (which stands for "change mode") changes who can access a particular file. A "mode" is created by combining the various options from who, opcode, and permission.

Structure:chmod [option] mode file

If you look at a list of files using the long list format ls -l, you'll see the permissions, owner, file size, modification time, and filename. The first column of the list shows who can read, write, and execute the files or directories - in other words, the permissions. It basically shows who has permission to do what to a given file or directory. r stands for "read" and means that you're allowed to read the file or directory. w stands for "write" and gives permission to edit or change the file as well as create, move, rename, or remove a directory. x stands for "execute," which gives permission to run a file or search a directory.

Every file or directory has four sets of rwx permissions. The first set represents the user (u), the second set represents the group (g), the third set represents other (o), and the fourth set represents all (a). The column will look like this:

rwxrwxrwx

Each set of rwx represents user, group, and other respectively. Only the owner of a file or a privileged user may change the permissions on a file.

There are two ways to change permissions on a file or directory, either numerically or by using lettered commands. Both ways use the command chmod. To add permissions to a file, you use +, to remove permissions you use-. Take this file for example:

-rw-r--r-- 1 meghan monkey 476 Oct 14 17:13 simian.html

To allow a group (monkey, in this case) "write" access, you would type:

chmod g+w simian.html

If you wanted to remove "read" ability from "other" you would type:

chmod o-r simian.html

It is also possible to specify permissions using a three-digit sequence. This is a more efficient way to change permissions (or at least it requires less typing), so use this method if it doesn't confuse you. Each type of permission is given an octal value. Read is given the value of 4, write is given the value of 2, and execute is given the value of 1. These values are added together for each user category. The permissions are changed by using a three-digit sequence with the first digit representing owner permission, the second digit representing group permission, and the third digit representing other permission. For example, if you wanted to make simian.html readable, writable, and executable for the user, readable and writable for the group, and readable for other, you would type:

chmod 764 simian.html

The first digit means readable and writable for the user (4+2+1), the second digit means readable and writable for the group (4+2), and the third digit means readable for other (4).

If you want to change the permissions on a directory tree use the -R option. chmod -R will recursively change the permissions of directories and their contents.

Back to Unix Guide

  • This page was last modified 18:40, 7 May 2008.
Edit this article
Reddit Digg
 
Subscribe now

Special Offer For Webmonkey Users

WIRED magazine:
The first word on how technology is changing our world.

Subscribe for just $10 a year