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 chapter The GNU/Linux filesystem: ext2fs which offers greater detail.

The first difference, and probably the most important, is related to the presence of users. We could have mentioned that every user has their own directory (called his home directory), but this doesn't say what really goes on, which is that each file on a Unix system, is the exclusive property of one user and one group. Therefore, not only does a user have his own home directory, but he's also the owner of his files in the real sense of the word.

Moreover, permissions are associated with each file which only the owner can change. 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 means every user who is neither the owner nor the member of the owner group.

There are three different permissions:

  1. Read permission (r) For a file, this allows its contents to be read. For a directory, this allows its contained files to be displayed, if and only if the execute permission is also set for this directory;

  2. Write permission (w) For a file, this allows its contents to be modified. For a directory, it allows the files contained therein to be modified and deleted, even if the person is not owner of the directory but owner of the file they modify or delete;

  3. eXecute permission (x) For a file, this allows for its 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).

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, and forbid every other use of the file. You can even do the opposite, even if it's not very logical at 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 a command line:

$ ls -l
total 1
-rw-r-----   1 queen    users           0 Jul  8 14:11 a_file
drwxr-xr--   2 darth    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:

Remember, there is one exception to this rule. The root account can change the 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.

In conclusion, we will mention a final distinction regarding filenames. They are more flexible and much less limited than under Windows:


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. 2000.
http://www.linux-mandrake.com/