LINUX TIPS AND TRICKS --- April 07, 2000

Published by ITworld.com, the IT problem-solving network
http://www.itworld.com/newsletters

*********************************************************************

File Permissions
by Danny Kalev

A file has an owner and a set of permissions. Linux associates three
categories of users with each file: an owner (the user who owns the
file), a group (the group of users to which the owner belongs), and
others (all the rest). For each category, three types of permissions
exist: read, write, and execute. Thus, you can selectively control who
can read, write, and execute the file. Suppose we have only one file in
the current directory called "bonuses" whose owner is susie. To see the
permissions of the current directory's files, use the following command:

  ls -l 

The command displays the files in six columns. The first column shows
the files' permissions, which appear as a string of ten characters. For
example: 

  -rw-r----- 

The first character tells whether the listed file is a directory. It can
have two values: - if it's an ordinary file, or the letter 'd' if it's a
directory. In our example, the file "bonuses" is an ordinary file.
Therefore, the string begins with a minus sign. The following nine
letters are divided into three parts: user's permissions, group's
permissions, and others' permissions. Each part has three characters,
and each character can have one of four values: 'r', 'w', 'x', '-'. In
our example, the first three characters after the initial directory
letter are "rw-". These are the user's permissions. In this case, susie
can read the file and write to it. The final minus indicates that she
can't execute the file (execute permission can be given to any file.
However, it makes sense only when the file is a program). The next three
Characters, "---", are the group's permissions. In this case, users of 
the group can't read the file, write to it, or execute it. The final 
three letters are the permissions granted to other users. Again, these 
users don't have any permissions.

- Changing File Permissions -
The "chmod" command changes a file's permissions. It takes a permission
string and the name of the file(s) whose permissions are changed.
Suppose susie wants to grant herself execute permission on a file called
"solitaire". She can do that by typing the following command:

  chmod u+x solitaire

The string "u+x" grants execute permission to the owner. To revoke this
permission, simply use - instead of +:

  chmod u-x solitaire

You can change permission for the owner, group, and others
simultaneously. The following command removes read and write access from
all the users:
 
  chmod ogu-rw solitaire

Likewise, you can grant execute permission to all users like this:

  chmod ogu+x solitaire

If this column has raised questions or comments, let's hear them. Join 
author Danny Kalev's Linux Software Development discussion on 
ITworld.com Forums. Current topic: To open or not to open?
http://forums.itworld.com/webx?14@@.ee6b652/1!skip=

About the author
----------------
Danny Kalev is a system analyst and software engineer with more
than 10 years of experience, specializing in C++ and
object-oriented analysis and design on various platforms including
VMS, DOS, Windows, Unix, and Linux. His technical interests involve
code optimization, networking, and distributed computing. He is
also a member of the ANSI C++ standardization committee and the
author of ANSI/ISO C++ Professional Programmer's Handbook (Que,
1999). Contact him at linuxnl@excite.com.
