2. File Basics

Abstract

Compared to Windows® and most other operating systems, files are handled very differently under GNU/Linux. In this section we will cover the most obvious differences. For more information, please read Chapter 9, The Linux File System.

The major differences result directly from the fact that Linux is a multiuser system: every file is the exclusive property of one user and one group. One thing we didn't mention about users is that every one of them possesses a personal directory (called the home directory). The user is the owner of this directory and all files created in it. Also note that these have an associated group as well and it is the primary group that the user belongs to. As it was mentioned before (see Section 1, “Users and Groups”), a user can be in more than one group at the same time.

However, this would not be very useful if that were the only notion of file ownership. As the file owner, a user may set permissions on files. These permissions distinguish between three user categories: 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 other user who is neither the owner nor a member of the owner group.

There are three different permissions:

  1. Read permission (r): enables a user to read the contents of a file. For a directory, the user can list its contents (i.e. the files in this directory).

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

  3. eXecute permission (x): enables a file to be executed (normally only executable files have this permission set). For a directory, it allows a user to traverse it, which means going into or through that directory. Note that this is different from the read access: you may be able to traverse a directory but still be unable to read its content!

Every permission combination is possible. For example, you can allow only yourself to read the file and forbid access to all other users. As the file owner, you can also change the owner group (if and only if you're a member of the new group).

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

$ ls -l
total 1
-rw-r-----   1 queen    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):

Lets take a closer look at the permissions associated with 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-----. Here's a breakdown of the permissions.

For the a_directory directory, the rights are rwxr-xr--, so:

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, and could therefore grant ownership of the file to himself! root can read files on which he has no read permissions, traverse directories which he would normally have no access to, and so on. And if root lacks a permission, he only has to add it. root has complete control over the system, which involves a certain amount of trust in the person wielding the root password.

Lastly, it's 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 fewer limitations.

[Note]Note

However it's worth noting that many graphical applications (file managers, office applications, etc.) actually use file extensions to recognize their files. It is therefore a good idea to use file-name extensions for those applications which support them.



[1] By default, hidden files won't be displayed in a file manager, unless you tell it to. In a terminal, you must type the ls -a command to see all hidden files besides normal files. Essentially, they hold configuration information. From your home/ directory, take a look at .mozilla or .openoffice to see an example.