Important note

These pages are deprecated (latest changes date from end 2001). More recent information may be found at http://www.coresequence.com/training.php. I leave the old pages here as they are because lots of people are still visiting them (eventhough they aren't spell-checked), and because the basics are still useful.

Introduction to the Unix File System

In this chapter, we will discuss the major parts of a Unix system. We will take a look at the filesystem and learn how to navigate through it.

Functions of an operating system

There are two things everybody knows about an operating system:

In Unix, the operating system consists of files, arranged in a tree structure. Everything is a file: programs, directories, images, texts, services etc. are all files. Sometimes a file with a special attribute, but a file nevertheless.

There are 3 major types of files.

The kernel

This is only one file, which is the core of the operating system and talks directly with the supporting hardware. It manages devices (special files), processes and daemons (executable files), swapspace (another special file type) and the rest of the filesystem. The kernel is also responsible for scheduling and executing commands at exactly the right time.

The shell

The shell is a wrapper to prevent painstaking user interaction with the underlying hardware. It translates user input to a form the kernel can understand by calling on to the suitable executable (program) for the user's command and passing this to the kernel. Supposing Unix were a car, then the shell would be the steering wheel. In the same picture, the kernel would be the engine.

The shell allows the user to interactively use the system, it provides means of customizing your environment and programming (cfr. batch-files in DOS).

There are a couple of different types of shells, the most important are:

  • sh or Bourne shell: the standard shell, the most compact but also the simpelest

  • ksh or Korn Shell: superset of the common shell, lets you edit the command line, usually using the vi editor, which makes it rather confusing for new users.

  • csh or C-shell: scripting and executing commands is done using C programming language syntax.

  • tcsh or turbo C shell: a superset of csh allowing easier scripting

  • bash or Bourne again shell: the GNU shell, allowing flexible and intuitive user interaction. As of this writing, bash is the most advanced shell and is the most recommendable shell for beginning users.

See Appendix 1 for common and differing shell features. The table with differing features has only 3 columns, because ksh and bash basicly follow the same rules, and the same goes for csh and tcsh. Reading the manual of your shell is an excellent way of getting to know your future environment.

The type of shell a user gets is determined in /etc/passwd, the database containing user login information. Some users (e.g. POP3 users, database users) get no shell or a shell that doesn't exist in order to prevent them from connecting directly to a system.

The filesystem

A Unix file can hold anything: text, programs, pictures, sound, a device, symbolic links, anything. It's just a bunch of raw data (ones and zeros) until the right program finds it.

A directory is also just a file, it only happens to store information about other files (cfr. folders in MS Windows).

Home directory vs. working directory

When you log on to the system, it places you in your homedirectory as a start, which is defined in the /etc/passwd file. It is your unique place in the filesystem and contains files you use all the time when logging in. You can make your own files here, edit or delete them, create and remove directories, this is your room and you're the boss in here.

Your working directory, on the other hand, can be anything. At the start of every session the working directory and the homedirectory are the same. As soon as you change to another directory, that directory becomes your working directory, and unless you tell the system otherwise, all commands that you enter will apply to the working directory.

Note

Working directory is called current or present working directory on some systems.

The directory tree

The directories on a Unix system are conveniently ordered into a tree structure. The parent directory of the tree is called the "root" directory and is written as a forward slash (/).

The root contains the entire filesystem. Some of the most important directories are listed below:

/ or /root on some systems: root's homedirectory. Keep in mind that the root of a filesystem is /, not /root.

/bin: binary files (program files)

/boot or /kernel: information for booting the system, directory for storing (the) kernel(s).

/dev: entries for all devices. Some systems use /devices and /dev, where /dev contains links to entries in /devices.

/etc: system configuration files, startup and shutdown procedures.

/home: (or /export/home or /users on some systems): user homedirectories

/lib: library files

/net: entries for other (networked) systems

/opt: third party software (used to be /usr/local), unbundled software

/proc: a pseudo-filesystem storing information about processes and devices

/sbin: system binaries

/tmp: temporary space, required on every Unix system

/usr: user binaries and libraries, manuals and docs

/var: variable files

Swap: virtual memory on a hard disk allowing the system to use more memory than the amount fysically available.

File system layout may differ across Unices, the above listing is only a guideline.

Most Unix systems offer some form of graphical filemanagement. Below is an example from the Gnome Nautilus filemanager.

Figure 1. Nautilus Filemanager