A - A - A

The Filesystem

 
Search

In order to provide you with a working knowledge of the Linux filesystem, the following topics will be introduced in this section.

  1. The Linux Root Filesystem

  2. Permissions

  3. Alternative Filesystems

Overview

The filesystem is made up of files and folders or directories. The top level folder is called the root folder and contains all of the files that are pertinent to your system. Each file within this system is allotted a name and a path on the basis of where it lies in relation to the root folder. Thus a sample file -alephlinux.txt- may be found at /home/letters/alephlinux.txt where the forward slash "/" before home denotes root.

Important: The new user must also appreciate that the filesystem is case-sensitive and therefore distinguishes between ALEPHLINUX.txt and alephlinux.txt.

Linux also provides support for long filenames although you should avoid the use of symbols like "@" within filenames, as they are used for other purposes.

The Linux Root Filesystem

The following schematic provides a simple representation of the most important directories and files which make up the root filesystem whilst the subsequent sub-section provides a brief description of the filesystem's structure. For more information about the root filesystem, enter man hier at the prompt for a full description.

Directories

/usr

Contains files and sub-directories which may be shared between machines. Important sub-directories include:

  • /usr/lib which contains programming and language libraries

  • /usr/local which provides the location for user-specific programs and files

  • /usr/include for C #include files

/etc

all configuration files should be in here (often in subdirectories)

/home

contains home directories for all users on the system. /home/paul would therefore be the home directory for user paul.

/bin

contains fundamental executable files (commands or programs) used by users. Only the basic ones are here, most are in /usr/local/bin, but usually a user doesn't care where the executable is actually stored. which <commandname> will tell you where an executable actually resides.

/sbin

includes executable files which are for system administration, as opposed to programs used by users. An example of this would be the shutdown command which closes the system down properly.

/mnt

location for mounting filesystems. For supplementary information, consult the section called Alternative Filesystems

/tmp

a directory which provides the temporary location for different programs. /tmp files tend to be deleted when the system is re-booted.

/dev

contains special pseudo files which give access to devices like the keyboard - /dev/kbd - and the virtual terminals - /dev/console, /dev/tty0 and /dev/tty1.

/var

a directory which contains files which can grow through usage. Typical examples include email message files and system accounting files.

  • /var/adm for per-process accounting records

  • /var/tmp for temporary files which are not deleted at re-boot time.

  • /var/spool for running system processes. /var/spool/mail would be a typical file in this sub-directory

Permissions

Although you should now have some appreciation of the Linux filesystem it is important to realise that Linux can be used in a multi-user or networked environment. It is therefore sensible to learn about the various types of role and permission which can be associated with a file so that the file owner can decide exactly who has access to files.

Any user may consequently fit into any one of three roles which include:

  1. the ownership role

  2. the group role

  3. the other role

The owner of a file can change file permissions at will. Moreover, a file may be associated with a group which is useful in a collaborative project context in which file access can be restricted to group members. Finally, the other role applies to a user who is neither the owner of the file nor the member of the group which is associated with the file.

In a similar vein, for every Linux file, three types of permission can be applied to each of the three roles. These permission switches are as follows

  1. R (Read): enables the user to read files, or (for a directory) to list files on the system

  2. W (Write): allows for the alteration or deletion of files, or (for a directory) deleting, adding and renameing of files

  3. Execute (Execute): allows for the execution of a file where it is an executable or for changing directories.

In order to clarify matters, this information can be most effectively presented in tabular form. Note that a dash in the line of text denotes the absence of a permission whilst r, w or e indicates that one of the three types of switch is activated.

Table 9-3. Permissions by Role

OwnerGroupOther
r w xr w xr - x

To illustrate all of the above, consider a situation where we want to know the permissions which apply to a particular file. After invoking the ls -l <filename> command, our hypothetical output might look some thing like the following:

—rw—r——r—— 1 paul paul 388 June 10 09:30 notes.txt

Reading across the listing from left to right, the first character position show the file's filetype which in this example is a normal file. Other possibilities include:

  1. d for a directory

  2. c for a device

  3. b for a socket

  4. s for a pipe

The remaining nine bits apply to the user, group and other roles respectively with three bits being alotted to each of the roles. Thus our hypothetical output shows that the user has read and write permissions whilst the group and other roles have read permission only. Note also that a dash denotes the absence of a permission.

If however, it becomes necessary to change file permissions, this can be accomplished by:

  1. setting file permissions with octal numbers

  2. setting file permissions with a combination of symbols

  3. setting the setuid, setgid and sticky bits

To alter a file's permissions with numbers, Linux uses four numbers which determine permission types including:

  1. 4: read permissions

  2. 2: write permissions

  3. 1: execute permissions

  4. 0: no permissions

Therefore, to alter the permissions status of our hypothetical file so that the group has read and write permissions, we would add 4 (read permission) and 2 (write permission) together before issuing the following command:

chmod 664 notes.txt

The following table summarises the situation thus far:

Table 9-4. Permissions by Numbers

RolePermissionCalculation
Owner64+2+0 (r+w+e)
Group64+2+0 (r+w)
Other44+0+0 (r)

In a situation where it is necessary to set permissions one role and one permission at a time, the symbolic permission notation can be used. In order to make use of this facility, the user need only remember that permissions may be granted or denied by using the following three symbols in conjunction with the read, write and execute switches that we have already encountered:

  1. u signifies the user/owner role

  2. g represents the group role

  3. o signifies the other role

Therefore, in order to allocate a group read and write permissions for the file notes.txt using symbolic notation, the user could enter the following command:

chmod g+rw notes.txt

Because many permutations are possible when using this method, the table below gives some indication of how permissions may be alterred. Note that "+" means that permission is granted whilst "-" shows that permission is denied.

Table 9-5. Permissions by Symbols

Granted/DeniedPermissionsString
user, group, otherread, write, executeugo+rwx
user, group, otherread, write, executeugo-rwx
user, groupread, writeug+rw
user, groupread, writeug-rw
userreadu+r
userreadu-r

Of course, there is much more that could be said about permissions but for further details on the specifics of topics like sticky bits, shadow passwords and filesystem maintenance, consult the relevant man page. Refer to the section called Help! for advice on using man.

The important thing to remember is that if you are having a problem with missing files or some other mysterious error, it is very often due to incorrect permissions somewhere in the system. Always remember to check.

Alternative Filesystems

ARMLinux can similarly make use of a range of filesystems in addition to its own Second Extended filesystem (ext2fs).

Under Linux the user will however have to mount a device before it can be accessed and used. This is done with the mount command but you will initially have to edit the /etc/fstab file as the root user in order to avail of this facility. This file is also used to specify which filesystems should be mounted automatically at boot time. To edit this file - which is just a text file - use Vim to open the file with the following command:

vim /etc/fstab

If your file doesn't include a line like the following:

/dev/hda1     /adfs     adfs       noauto,user   0   0

then you should add one in order to be able to read your RISC OS drive from ARMLinux. Note that if your RISC OS drive is RISC OS 4 with long filenames then this is not supported at the time of writing so you can skip this section. The format of this file is explained in man fstab.Save and quit by depressing the ESC key, waiting for a beep and then typing :wq /etc/fstab. Where this line is missing, type it in from scratch noting that there should be no spaces between noauto any punctuation and user. if you want this drive to be automatically mounted on boot then change the final 0 to a 1. You will then need to make a mount directory.

mkdir /adfs

Congratulations, you are now in a position to mount your RISC OS filesystem with the following command:

mount /adfs

You can now access your files from the /adfs directory.

Debian Package Management

In order to take full advantage of Debian, you need to learn a little about the package management system which underpins it. Debian packages everything in .DEB files. These packages are controlled by a program called dpkg, or from a friendlier front-end such as dselect or apt. The system is extremely powerful; every file on your system is known about by the system and it takes care of a great deal of complexity when installing, removing or upgrading software. It knows about the interdependencies between pieces of software and if you ask to install something it will also get the other things it needs. It knows which files are configuration files and will not overwrite them when upgrading a package. It can also upgrade a running system without breaking things and lets you find out what is on your system. To a large extent the package management system is what makes Debian special and once you understand it you will find it a marvellous facility.

dselect is the interface that you will first use. It was designed when Debian had 500 rather than 5000 packages and suffers a bit because of this, but it is quite straightforward to use and a good introduction to the package system. Later you will just use apt to install new software. Once apt has been taught where to get software (usually off the CD and off the net) you can say things like apt-get install <software> and it will go away and get it for you, then install it, install anything else necessary and configure them all, often without asking you any further questions apart from telling you which CD to insert or if the download size is OK.

It is important to understand however that if you want to install software that is not in the Debian archive then everything is not taken care of for you and you will have to understand what is going on and do some work yourself. For example, if obtaining a package from a distribution which is meant for x86-based PCs, you will have to compile it from source as the binary versions supplied will not work on an ARM-based machine. Such a procedure is outside this manual's scope but - assuming that you want to use a package which is on the ARMLinux CD or in the huge Debian archive - read on!

dpkg can for example be used to install a package by using the i (or --install) switch.

dpkg -i /cdrom/debian/dists/potato/main/binary-arm/utils/mc<TAB>

Note that the <TAB> above means press the TAB key, not type in those letters. This uses the shell's filename expansion facility to fill in the end of the filename. It's a marvellous facility. If it beeps then there is more than one possible answer - press <TAB> again to see the list. It even works on commands.

However, it is standard practice to use apt instead to save typing long pathnames, like this:

apt-get install mc

Here apt knows where to look for packages, finds mc and then uses dpkg to actually do the installation, but saves you worrying about the actual location of the package.

What you have just done is to use dpkg to install Midnight Commander (mc) - a visual shell which does not need X Windows - on your system. Conversely, you may choose to delete or uninstall a package which can be accomplished by using the -r (or --remove) switch. The following command consequently removes mc.

dpkg -r mc

Don't be too hasty however. MC is an excellent way of navigating the filesystem when used in conjunction with the shell. So why not learn a bit about it before using dpkg's -r switch?

Congratulations, you've managed to mount your filesystem and have a look at some files. Before removing your CD-ROM, you will need to use the umount command which can either be used to unmount the current filesystem or a specific directory. But please be careful with your typing and key in umount rather than unmount. If it tells you that the filesystem is busy then your current directory is probably in the mounted filesystem. You need to change directory elsewhere before you can umount.

umount /dev/cdrom

or

umount /cdrom

In order to find out about other filesystem types and the specifics of the mount and umount commands, you can take advantage of the range of commands and applications which are briefly described in the section called Help!.