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 4, 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 may 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:
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).
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.
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 to 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):
The first ten characters
represent the file's type and the permissions associated with it. The
first character is the file's type: if it's a regular file, you will
see a dash (-
). If it's a directory, the leftmost
character will be a d
. There are other file types,
which we'll discuss later on. The next nine characters represent
permissions associated with that file. The nine characters are
actually three groups of three permissions. The first group represents
the rights associated with the file owner; the next three apply to all
users belonging to the owner group; and the last three apply to
others. A dash (-
) means that the permission is not
set.
Next comes the number of links for the file. Later on we'll see that the unique identifier of a file is not its name, but a number (the inode number), and that it's possible for one file on disk to have several names. For a directory, the number of links has a special meaning, which will also be discussed a bit further.
The next piece of information is the name of the file owner followed by the name of the owner group.
Finally, the size of the file (in bytes) and its last modification time are displayed, with the name of the file or directory itself as the last item on the line.
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.
The first three characters
(rw-
) are the owner's rights, which in this case is
queen. Therefore, queen has the right to read the file
(r
), to modify its content (w
)
but not to execute it (-
).
the next three characters
(r--
) apply to any user who is not queen but
who is a member of the users
group. They will be
able to read the file (r
), but will not be able to
write nor execute it (--
).
the last three
characters (---
) apply to any user who is
not queen and is not a member of the
users
group. Those users don't have any
rights on the file at all, for them the file will be
“invisible”.
For the a_directory
directory, the rights are rwxr-xr--
, so:
peter, as the directory owner,
can list files contained inside (r
), add to or
remove files from that directory (w
), and may
traverse it (x
).
Each user who isn't peter, but
is a member of the users
group, will be able to
list files in this directory (r
), but not remove or
add files (-
), and will be able to traverse it
(x
).
Every other user will only be able to
list the contents of this directory (r
). Because
they don't have wx
permissions, they won't be able
to write files or enter the directory.
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.
A file name may contain
any character, including non-printable ones, except for the
ASCII character 0, which denotes the end of a string, and
/, which is the directory separator. Moreover,
because UNIX® is case sensitive, the files
readme
and Readme
are
different, because r
and R
are
considered two different characters on
UNIX®-based systems.
As you may have
noticed, a file name does not have to include an extension,
unless that's the way you prefer to name your files. File
extensions don't identify the content of files under
GNU/Linux, nor almost any other operating system. So-called
“file extensions” are quite convenient
though. The period (.
) under UNIX® is
just one character among others, but it also has one special
meaning. Under UNIX®, file names beginning with a period
are “hidden files”[1], which also includes directories whose names start
with a .
[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.