2.3.3. The file system#

If you paid attention during Exercise 2.7, you might have noticed that all of Synaptic’s files are installed in folders (in Unix we call them directories) such as /usr/sbin and /usr/share. Unlike Windows, where program files are stored per application, in Unix they are stored according to their use: all binaries go in one directory, all documentation files in another, etc. A general list of what goes where can be found in the filesystem overview below.

The Linux filesystem

The Linux filesystem assigns specific directories to contain specific important system files, such as executables, hardware drivers, log files, etc.

.
|-- bin           Essential user command binaries.
|-- boot          Static files of the boot loader.
|-- dev           Device files, for talking to hardware.
|-- etc           Host-specific system configuration.
|   \-- rc.d        Startup configuration
|-- home          Where you hang your hat. User directories.
|-- lib           Essential shared libraries and kernel modules.
|-- media         Removeable media (CD-ROM, USB, etc.).
|-- mnt           Temporarily mounted (network) filesystem.
|-- opt           Add-on application software packages.
|-- proc          Kernel and process information (virtual).
|-- root          Home directory for administrator.
|-- sbin          System binaries.
|-- srv           Data for services (WWW, FTP, etc.).
|-- sys           Kernel and device information (virtual).
|-- tmp           Temporary files.
|-- usr           Shareable, read-only data.
|   |-- bin          Most user commands.
|   |-- include      Header files included by C programs.
|   |-- lib          Libraries.
|   |-- local        Local hierarchy, not managed by OS.
|   |-- sbin         Non-vital system binaries.
|   |-- share        Architecture-independent data.
|   |   |-- doc      Miscellaneous documentation.
|   |   `-- man      Online manuals.
|   `-- src          Source code.
`-- var           Variable data files.
    |-- lock      Lock files.
    |-- log       Log files and directories.
    |-- mail      User mailbox files.
    |-- run       Data relevant to running processes.
    `-- spool     Application spool data (printer, mail, etc.).

The most important directory for you is your home directory, in /home/username (note that in Unix , subdirectories are separated by forward slashes!). This and the temporary directory /tmp are the only places you are allowed to place your files\footnote{More about file system permissions in Section 2.5.1.3}. This is especially important in multi-user systems, where you want to keep check on who may access your data. It is quite common for each user to install his or her private software in the same way as the /usr directory hierarchy, so a /home/username/bin, /home/username/share, etc.

Remember that Unix originated in an academic networked environment. To avoid having to install the same software on all computers, everything was often placed on a single server. No matter which computer you logged in to, you always had access to the same files and programs. This is what required the strict separation into essential (/bin, locally installed) and shareable (/usr/bin, can be on the network) program files, and local program (/var) and user (/home) data. Nowadays the separation is less strict, and is more about managed (/usr) and unmanaged (/usr/local) packages. If program files are placed on the network, it is usually restricted to the /usr/local hierarchy.

The easiest way to navigate the file system is using the File Browser, which can be accessed by clicking on the folder icon in the launcher. It works much like you are used to with Windows.

Exercise 2.11

Take a while to browse through the file system: go to File System to see the directory hierarchy. Try to navigate to the text file you saved in Exercise 2.1. Also try to read the administrator’s files (use the Linux filesystem overview to find where they are). What happens?

2.3.3.1. Mount points#

You might have noticed that there are no drives in Unix . Instead, every file system (partition, USB disk, network share) is mounted at a particular point in the directory hierarchy. This makes it easy for e.g. /usr to contain data from a local hard drive, while /home is located on a file server. Ubuntu places the most commonly mounted file systems (CD-ROMs, USB disks, and other partitions on the local hard drive) in a special /media directory.

Exercise 2.12

Connect a USB disk to the computer, and find out where it’s mounted.

2.3.3.2. Virtual file systems#

Files are very important in Unix , so much so that things that aren’t really files are presented like them anyway. One example are the device files in the /dev directory: things like a mouse or sound card have their own files that programs can read from or write to. They’re not human-readable, however. /proc, on the other hand, is comprehensible: it is a virtual file system, created by the kernel to give status information. You can navigate it like any other directory hierarchy, but every numbered directory corresponds to a running program.

Exercise 2.13

Open the cpuinfo file on the /proc filesystem. What does it say about your processor?