Unix/Linux File System Organization

The Unix/Linux file system is organized as a tree, which is shown (sideway) in Fig. 1.6.

Unix/Linux considers everything that can store or provide information as a file. In a general sense, each node of the file system tree is a FILE. In Unix/Linux, files have the following types.

1. File Types

  • Directory files: A directory may contain other directories and (non-directory) files.
  • Non-directory files: Non-directory files are either REGULAR or SPECIAL files, which can only be leaf-nodes in the file system tree. Non-directory files can be classified further as
    • REGULAR files: Regular files are also called ORDINARY files. They contain either ordinary text or executable binary code.
    • SPECIAL files: Special files are entries in the /dev directory. They represent I/O devices, which are further classified as

CHAR special files: I/O by chars, e.g. /dev/tty0, /dev/pts/1, etc.

BLOCK special files: I/O by blocks, e.g. /dev/had, /dev/sda, etc.

Other types such as network (socket) special files, named pipes, etc.

  • Symbolic LINK files: These are Regular files whose contents are pathnames of other files. As such, they act as pointers to other files. As an example, the Linux command

ln -s aVeryLongFileName myLink

creates a symbolic link file, mylink, which points to aVeryLongFileName. Access to myLink will be redirected to the actual file aVeryLongFileName.

2. File Pathnames

The root node of a Unix/Linux file system tree, symbolized by /, is called the root directory or simply the root. Each node of the file system tree is specified by a pathname of the form

/a/b/c/d OR a/b/c/d

A pathname is ABSOLUTE if it begins with a /. Otherwise, it is RELATIVE to the Current Working Directory (CWD) of the process. When a user login to Unix/Linux, the CWD is set to the user’s HOME directory. The CWD can be changed by the cd (change directory) command. The pwd command prints the absolute pathname of the CWD.

3. Unix/Linux Commands

When using an operating system, the user must learn how to use the system commands. The following lists the most often used commands in Unix/Linux.

ls: ls dirname: list the contents of CWD or a directory

cd dirname: change directory

pwd: print absolute pathname of CWD

touch filename: change filename timestamp (create file if it does not exist)

cat filename: display file contents

cp src dest: copy files

mv src dest: move or rename files

mkdir dirname: create directory

rmdir dirname: remove (empty) directory

rm filename: remove or delete file

ln oldfile newfile: create links between files

find: search for files

grep: search file for lines containing a pattern ssh: login to remote hosts gzip filename: compress filename to .gz file gunzip file.gz: uncompress .gz file

tar -zcvf file.tgz . : create compressed tar file from current directory

tar -zxvf file.tgz . : extract files from .tgz file

man: display online manual pages

zip file.zip filenames : compress files to .zip file

unzip file.zip : uncompress .zip file

4. Linux Man Pages

Linux maintains online man (manual) pages in the standard /usr/man/directory. In Ubuntu Linux, it is in /usr/share/man directory. The man pages are organized into several different categories, denoted by man1, man2, etc.

/usr/man/

|– manl: commonly used commands: ls, cat, mkdir         etc.

|– man2: system calls

|– man3: library functions: strtok, strcat, basename, dirname etc.

All the man pages are compressed .gz files. They contain text describing how to use the command with input parameters and options. man is a program, which reads man page files and displays their contents in a user friendly format. Here are some examples of using man pages.

man ls         :        show man page of ls in man1

man 2 open :       show man page of open in man2

man strtok  :        show man page of strtok in man 3, etc.

man 3 dirname : show dirname in man3, NOT that  of man1

Whenever needed, the reader should consult the man pages for how to use a specific Linux command. Many of the so called Unix/Linux systems programming books are essentially condensed versions of the Unix/Linux man pages.

Source: Wang K.C. (2018), Systems Programming in Unix/Linux, Springer; 1st ed. 2018 edition.

Leave a Reply

Your email address will not be published. Required fields are marked *