2.2. File Basics

Files are another topic where GNU/Linux differs greatly from Windows and most other operating systems. We will cover the most obvious differences here. For more information, see the The Linux filesystem chapter, which offers greater detail.

The major difference results direct from the fact that Linux is a multiuser system: every file is the exclusive property of one user and one group. And one thing we did not mention about users and groups is that every one of them possesses a personal directory (called home directory). He is the owner of this directory, and of all files he will subsequently create.

However, this would not be very useful if there were only that notion of file ownership. But there is more: as the file owner, a user can set permissions on her files. These permissions distinguish three categories of users: the owner of the file, every user who is a member of the group associated with the file (also called the owner group) but who is not the owner, and others, which includes every user who is neither the owner nor member of the owner group.

There are three different permissions:

  1. Read permission (r): it enables the contents of a file to be read. For a directory, this allows its contents (i.e. the files in this directory) to be listed.

  2. Write permission (w): it allows the modification of a file's contents. For a directory, the write permission allows a user to add and/or remove files from this directory, even if she is not the owner of these files.

  3. eXecute permission (x): it enables a file's execution (as a consequence, only executable files should normally have this permission set). For a directory, this allows a user to traverse it (which means going into or through that directory). Note that this is separated from the read access: it may very well be that you can traverse a directory but cannot read its contents!

Every combination of these permissions is possible. For example, you can allow only yourself to read the file and forbid it to all other users. You can even do the opposite, even if it's not very logical at a first glance... As the file owner, you can also change the owner group (if and only if you are a member of the new group), and even deprive yourself of the file (that is, change its owner). Of course, if you deprive yourself of the file, you will lose all your rights to it...

Let's take the example of a file and a directory. The display below represents entering the ls -l command from the command line:

toi$ ls -l
total 1
-rw-r-----   1 pingusa    users           0 Jul  8 14:11 a_file
drwxr-xr--   2 peter    users        1024 Jul  8 14:11 a_directory/
$            

The results of the ls -l command are (from left to right):

Let us now look closely at the permissions associated to each of these files: first of all, we must strip off the first character representing the type, and for the file a_file, we get the following rights: rw-r-----. The interpretation of these permissions is as follows:

For the directory a_directory, the rights are rwxr-xr--, and as such:

There is one exception to these rules: root. root can change attributes (permissions, owner and group owner) of all files, even if he's not the owner. This means that he can also grant himself the ownership! He can read files on which he has no read permission, traverse directories which he would normally have no access to, and so on. And if he lacks a permission, he just has to add it...

Lastly, it is worth noting the differences between file names in the Unix and the Windows worlds. For one, Unix allows for a much greater flexibility and has less limitations:


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2001.
http://www.mandrakelinux.com/