A Sample from the book

Linux files are organized logically for ease of administration. This file organization is maintained in hundreds of directories located in larger containers called file systems. Red Hat Enterprise Linux follows the File system Hierarchy Standard (FHS) for file organization, which describes names, locations, and permissions for many file types and directories. File systems are primarily of two types: disk-based and memory-based, and they are used to store permanent and runtime data.

Files are static and dynamic, and are referenced using absolute and relative pathnames. Linux supports several different types of files and their type is based on the type of data they store. There are a number of operations that can be performed for managing files and directories. Linux includes thousands of files and each file has certain default attributes that can be viewed or modified. There are tools available that prove to be very helpful in searching for files within a specified boundary and in linking them as desired.

Permissions are set on files and directories to restrict their access to authorized users only. Users are grouped into three distinct categories. Each user category is then assigned required permissions. Permissions can be modified using one of two available methods. The user mask may be defined for individual users so that the new files and directories they create always get preset permissions. Every file in Linux has an owner and a group associated with it. The OS offers three additional permission bits to control user access to certain executable files and shared directories. A directory with one of these permission bits set can be used for group collaboration.

File System Tree

Linux uses the conventional hierarchical directory structure where directories may contain both files and sub-directories. Sub-directories may further hold more files and sub-directories. A sub-directory, also referred to as a child directory, is a directory located under a parent directory. That parent directory is a sub-directory of some other higher-level directory. In other words, the Linux directory structure is similar to an inverted tree where the top of the tree is the root of the directory, and branches and leaves are sub-directories and files, respectively. The root of the directory is represented by the forward slash ( / ) character, and this is the point where the entire file system structure is ultimately connection. The forward slash character is also used as a directory separator in a path such as /etc/rc.d/init.d/network.

In this example, the etc sub-directory is located under /, making root the parent of etc (which is a child). rc.d (child) is located under etc (parent), init.d (child) is located under rc.d (parent), and at the very bottom, network (leave) is located under init.d (parent).

Each directory has a parent directory and a child directory, with the exception of the root and the lowest level directories. The root directory has no parent and the lowest level sub-directory has no child.

The term sub-directory is used for a directory that has a parent directory.

The hierarchical directory structure keeps related information together in a logical fashion. Compare this concept with a file cabinet that has several drawers, with each drawer storing multiple file folders.

Two file systems, / and /boot, are created during a default RHEL installation. However, the custom installation procedure covered in Chapter 01 “Installing RHEL7 on Physical Computer Using Local DVD” allows us to create /var, /usr, /tmp, /opt, and /home file systems besides / and /boot. The main directories under the / and other file systems are shown in Figure 3-1. Some of these directories hold static data while others contain dynamic (or variable) information. Static data refers to file contents that are usually not modified, and dynamic or variable data refers to file contents that are modified and updated as required. Static directories normally contain commands, library routines, kernel files, device files, etc., and dynamic directories hold log files, status files, configuration files, temporary files, and so on.

A brief description of disk-based and virtual file systems is provided in the following sub-sections.

The Root File System (/) – Disk-Based

The root file system is the top-level file system in the FHS and contains many higher-level directories holding specific information. Some of the key directories are:

/etc: The etcetera directory holds system configuration files. Some common sub-directories are: systemd, default, lvm, and skel, which contain configuration files for systemd, defaults for user accounts and some other services, the Logical Volume Manager, and per-user shell startup template files, respectively.

/root: This is the default home directory location for the root user.

/media: This directory is used by the system to automatically mount removable media such as floppy, CD, DVD, USB, and Zip drives.

/mnt: This directory is used to mount a file system temporarily.

The Boot File System (/boot) – Disk-Based

The /boot file system contains the Linux kernel, boot support files, and boot configuration files. The default size of this file system is 500MB, and it may be expanded as part of the preparation to update the kernel.

The Variable File System (/var) – Disk-Based

/var contains data that frequently changes while the system is operational. Files holding log, status, spool, lock, and other dynamic data are located in this file system.

Some common sub-directories under /var are:

/var/log: This is the storage for most system log files such as system logs, boot logs, failed user logs, user logs, installation logs, cron logs, mail logs, etc.

/var/opt: For additional software installed in /opt, this directory stores log, status, and other variable data files for that software.

/var/spool: Directories that hold print jobs, cron jobs, mail messages, and other queued items before being sent out are located here.

/var/tmp: Large temporary files or temporary files that need to exist for longer periods of time than what is allowed in /tmp are stored here. These files survive system reboots and are not automatically deleted.

The UNIX System Resources File System (/usr) – Disk-Based

This file system contains general files related to the system, with some portions perhaps shared with other remote systems. This file system is mounted read-only. Some of the important sub-directories under /usr are:

/usr/lib: The library directory contains shared library routines required by many commands and programs located in the /usr/bin and /usr/sbin directories, as well as by the kernel and other programs.

/usr/bin: The binary directory contains crucial user executable commands.

/usr/sbin: Most commands required at system boot are located in this system binary directory as well as most commands requiring root privileges to run. In other words, this directory contains crucial system administration commands that are not intended for execution by regular users (although they can still run a few of them). This directory is not included in the default search path for normal users because of the nature of data it contains.

/usr/local: This directory serves as a system administrator repository for storing commands and tools downloaded from the web, developed in-house, or obtained elsewhere. These commands and tools are not generally included with the original Linux distribution. In particular, /usr/local/bin holds executables, and /usr/local/etc contains their configuration files.

/usr/include: This directory contains header files for C language.

/usr/src: This directory is used to store source code.

/usr/share: This is the directory location for man pages, documentation, sample templates, configuration files, etc. that may be shared on multi-vendor Linux platforms with heterogeneous hardware architectures.

The Optional File System (/opt) – Disk-Based

This file system holds additional software installed on the system. A sub-directory is created for each installed software.

The Home File System (/home) – Disk-Based

The /home file system is designed to hold user home directories. Each user account is assigned a home directory in which to save personal files. Each home directory is owned by the user the directory is assigned to, with no access to other users.

The Devices File System (/dev) – Virtual

The /dev file system contains device nodes for physical hardware and virtual devices. The Linux kernel communicates with these devices through corresponding device nodes located here. These device nodes are created and deleted by the udevd service as necessary.

There are two types of device files: character (or raw) device files and block device files. The kernel accesses devices using either or both types of device files.

Character devices are accessed serially, with streams of bits transferred during kernel and device communication. Examples of such devices are serial printers, mice, keyboards, terminals, tape drives, etc.

Block devices are accessed in a parallel fashion, with data exchanged in blocks (parallel) during kernel and device communication. Data on block devices is accessed randomly. Examples of block devices are hard disk drives, optical drives, parallel printers, etc.

The Process File System (/proc) – Virtual

The /proc file system maintains information about the current state of the running kernel, including details on CPU, memory, disks, partitioning, file systems, networking, and running processes. This virtual file system contains a hierarchy of sub-directories containing thousands of zero-length files pointing to relevant data that is maintained by the kernel in the memory. This virtual directory structure simply provides us with an easy interface to interact with kernel-maintained information. The /proc file system is automatically managed by the system.

The contents in /proc are created in memory at boot time, updated during runtime, and destroyed at reboot time. Underneath this file system are stored current hardware configuration and status information. A directory listing of /proc is provided below:

# ll /proc

dr-xr-xr-x.  8 root           root                         0 Nov 17 14:22 1

dr-xr-xr-x.  8 root           root                         0 Nov 17 14:22 10

dr-xr-xr-x.  8 root           root                         0 Nov 17 14:23 1000

dr-xr-xr-x.  8 root           root                         0 Nov 17 14:23 1009

. . . . . . . .

As mentioned, this file system contains thousands of files and sub-directories. Some sub-directory names are numerical and they point to information about specific processes, with process IDs matching the sub-directory names. Within each sub-directory, there are files and further sub-directories, which include information such as memory segment specific to that particular process. Other files and sub-directories point to configuration data for system components. If you wish to view configuration information for a specific item such as the CPU or memory, you can cat the contents of cpuinfo and meminfo files as shown below:

# cat /proc/cpuinfo

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 6

model             : 42

model name    : Intel(R) Core(TM) i7-2760QM CPU @ 2.40GHz

stepping          : 7

cpu MHz         : 2423.437

. . . . . . . .

# cat /proc/meminfo (also shows available memory)

MemTotal:         7889040 kB

MemFree:            757800 kB

MemAvailable:  1451248 kB

. . . . . . . .

The data located under /proc is referenced by a number of system utilities, including top, ps, uname, and vmstat, for display purposes.

The System File System (/sys) – Virtual

Information about configured hotplug hardware devices is stored and maintained in the /sys file system. This information is referenced for loading kernel modules, creating device nodes in the /dev directory, and configuring each device. This file system is auto-maintained as well.

The Temporary File System (/tmp) – Virtual

This file system is a repository for temporary storage. Many programs create temporary files as they run or while they are being installed. The contents of this file system are automatically deleted at system reboots.

Google Book Search