Learning Linux

Part 5 - The Linux File System

General Information

One description of the Linux operating system is this:

There are special files that are more than just files (like named pipes and sockets), but in general saying that everything is a file in Linux is acceptable. Linux does not distinguish between files and directories, and programs, texts, services and images are also files. Even input and output devices are considered to be files.

When you attempt to manage all the files, it is easier to think of the Linux file system as a tree-like structure, with branches. The files are the leaves of the tree. This is also a generalization, which we can explore later.

File Types

Most files in Linux are just files, which we call regular files. The contain normal information such as text, program, input/output from a program or images.

While it is reasonably safe to consider that everything you encounter on Linux is a regular file, there are some exceptions.

When you list files with the 'ls' command using the '-l' (long file listing) option, you will get a list with file type/permissions at the start of each file:

mburton@pitr ~ $ ls -l
total 228
drwxr-xr-x 3 mburton mburton 4096 Feb 21 2013 Calibre Library
drwxr-xr-x 2 mburton mburton 4096 Sep 19 09:05 Desktop
drwxr-xr-x 17 mburton mburton 4096 Nov 25 11:57 Documents
drwxr-xr-x 23 mburton mburton 4096 Oct 9 09:05 Downloads
drwxr-xr-x 54 mburton mburton 4096 Jul 16 08:14 e-books
drwxr-xr-x 9 mburton mburton 4096 Mar 11 2013 eclipse
-rwxr--r-- 1 mburton mburton 1383 Mar 31 2010 feet.sh

The first letter or symbol in each line is the file type. The rest of the letters/symbols are file permissions, which we will discuss later. The file type letters/symbols are

Symbol Meaning
- Regular file
d Directory
l Link
c Special file
s Socket
p Named pipe
b Block device

File Properties and Permissions

The remaining nine letters are the file permissions. They are grouped as three groups with three letters each. The groups are

Letters Meaning
First Three User (owner) permissions
Second Three Group permissions
Third Three Permissions for others

The letters for each group have specific meanings. They are

Letter Meaning
r (or -) Read permission (or no read permission)
w (or -) Write permission (or no write permission)
x (or -) Execute permission (or no execute permission)

For example, if you are not the owner of a file, but are a member of the users group, and the file permissions are 'r-x', then you have permission to read or execute the file, but you cannot write to it.

File System Layout

The Linux basic filesystem structure is based on the original UNIX filesystem structure. It divides up the various files into a coherent structure.


Figure 1. Filesystem Structure

/ - The filesystem's root directory

The root directory is the base of the Linux filesystem. All files and directories are under the root directory. The root user is the only user that has write permission for this directory. This is not the root user's home directory. /root is the root user's home directory.

/bin - The user binary directory

The /bin directory contains executable files (binaries and scripts) that all users can execute. Common Linux command-line commands are located in this directory. Examples are ls, pwd, grep, cp.

/sbin - The system binaries directory

Like the /bin directory, the /sbin contains executable files (binaries and scripts). However, the files in this directory can only be executed by a system system administrator, such as the root user. Examples of system binaries include iptables, reboot and fdisk.

/etc - The configuration files directory

The configuration files directory contains the configuration files that are required by all Linux programs. It also contains start up and shut down shell scripts that are used to start and stop individual programs.

/dev - The device files directory

The device files directory contains files for the physical devices hooked up to your computer. These include terminal devices, usb, mass storage or any other device attached to the system.

/proc - The process information directory

The process information directory is a pseudo directory that contains information about running processes. It is a virtual filesystem with text information about system resources.

/var - The variable files directory

The variable files directory contains files that are expected to grow with use. Files such as system log files, packages and database files, emails, print queues, lock files and temp files that are needed across reboots.

/tmp - The temporary files directory

The temporary files directory contains temporary files that are created by the system and the users. All files under this directory are deleted whenever the system is rebooted.

/usr - The user programs directory

The user programs directory contains executable programs, libraries, documentation and source code for second level programs. If you can't find a particular program in /bin then look under /usr/bin. The /usr/sbin directory contains executable files for system administrators. If you can't find a program under /sbin then look for it in /usr/sbin. Libraries for programs in /usr/bin and /usr/sbin are in /usr/lib. User programs installed from source are put in /usr/local.

/home - The home directory

The home directory contains a sub-directory for each user that has a login to the system. The sub-directory is the same name as the user, and it contains all of the user's personal files.

/boot - The boot loader directory

The boot loader directory contains files relating to the process of booting Linux into operation. Files such as the kernel, initrd, vmlinux and grub are located in the boot directory.

/lib - The system libraries directory

The system libraries directory contains libraries for the programs located in the /bin and /sbin directories. The file names will contain either 'ld' or 'lib' and usually have '.so' in the name.

/opt - The optional add-on applications directory

The optional add-on applications directory contains extra and third party software. The additional software will be installed in sub-directories of the /opt directory.

/mnt - The mount directory

The mount directory is used by system administrators to temporarily mount filesystems. It doesn't see much use in modern Linux systems.

/media - the removable media devices directory

The removable media devices directory is used to temporarily mount removable devices, such as memory sticks, CD-ROMS and floppy drives. You may also see connections to digital cameras and tablets in this directory.

/srv - The service data directory

The service data directory contains data relating to specific services. For instance, if you are using CVS, there will be data in /srv/cvs concerning CVS usage.



<< Part 4: More of the GIMP