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 differences result directly 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 the files. These permissions distinguish between 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 other user who is neither the owner nor member of the owners' group.
There are three different permissions:
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.
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 they are not the owner of these files.
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 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 to it. The first character is the file's type: if it is a regular file, it will contain a dash (-). If it's a directory, you will see this character: d. There are other file types, which we will talk about in the Reference Manual. The nine following characters represent the permissions associated to that file. Here you can see the distinction which is made between different users for the same file: the first three characters represent the rights associated to the file owner, the next three apply to all users belonging to the group but who are not the owner, and the last three apply to others. A dash (-) means that the permission is not set;
following this are the number of links for the file. We will see in the Reference Manual that the unique identifier of a file is not its name, but a number (the inode number), and that it is possible for one file on disk to have several names. For a directory, the number of links has a special meaning, which we will also discuss in the Reference Manual;
following this is the name of the file owner and the name of the owner group;
finally, the size of the file (in bytes) and its last modification time are displayed, followed lastly by the name of the file or directory itself.
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:
the first three characters (rw-) are the file owner's rights, in this case queen. Therefore, queen has the right to read the file (r), to modify its contents (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 : such a user will be able to read the file (r), but neither 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: such a user will simply have no rights on the file at all.
For the directory a_directory, the rights are rwxr-xr--, and as such:
peter, as the directory owner, can list files contained inside (r), add or remove files from that directory (w), and he can traverse it (x);
each user who is not peter, but a member of the users group, will be able to list files in this directory (r), but not remove nor 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), but that's all. He will not even be able to 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. 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:
a file name may contain any character (except ASCII character 0, which is the end of a string, and /, which is the directory separator), even non-printable ones. Moreover, UNIX is case sensitive: the files readme and Readme are different, because r and R are read as two different characters under UNIX-based systems.
As you may have noticed, a file name does not have to include an extension unless you prefer it that way. File extensions do not identify the contents of files under GNU/Linux, and neither do they on any operating system for that matter. So-called "file extensions" are always very convenient, though. The period (.) under UNIX is just one character among others. It is worth mentioning that file names beginning with a period under UNIX are "hidden files";