The File System - LINUX: The Ultimate Beginner’s Guide! (2015)

LINUX: The Ultimate Beginner’s Guide! (2015)

Chapter 3: The File System

In this chapter, you’ll learn about the files and directories used in Linux systems. Many users experience difficulties with this type of OS because they don’t know what kind of information is stored in what areas. This chapter will explain how files are organized in Linux’s file system.

The File System – General Overview

Files

Here’s a simple description for Linux systems:

“In Linux systems, everything is considered as a file. If it is not a file, it is considered as a procedure.”

The statement given above is correct because of the existence of special files (e.g. pipes and sockets). At this point, Linux users consider this statement as an acceptable generalization. Similar to Unix, Linux treats files and directories the same way, because directories are just files that contain the names of other files. Texts, images, programs, and services, are files. Additionally, Linux systems consider all devices (i.e. input and output devices) as files.

To manage files in an organized way, the manual “thinks” of them using a systematic tree-like structure on the computer’s hard drive. This method is also being used by MS-DOS. The big branches contain other branches, and the smallest branches found at the end contain normal files.

Different Types of Files

Majority of the files are regular files: they hold ordinary data such as programs, text files, and outputs from a task.

Although it is safe to assume that all you see in a Linux system are files, there are some exceptions:

· Links – A method to show files and directories in various parts of the OS’s file tree.

· Sockets – This is a special type of file. They provide inter-process networking secured by the OS’s security control.

· Directories – These contain the names of other files.

· Special files – The device used for inputs and outputs. Almost all special files are found in /dev. This will be discussed later.

· Named pipes – They act like sockets: they allow processes to interact with each other.

The -1 option of the “Is” command shows the file type. Here’s a screenshot:

The list given below shows some of the characters used for identifying file types:

· Hyphens (i.e. “-”) are used for regular files.

· The letter “d” is used for directories.

· The letter “l” is used for links.

· The letter “c” is used for special files.

· The letter “s” is used for sockets.

· The letter “p” is used for pipes.

· The letter “b” is used for block devices.

The Layout of the File System

For convenience, the file system for Linux operating systems is considered as a tree-like structure. For typical Linux systems, the layout follows the scheme below:

That layout is being used by the RedHat system. The structure may change and directories may be added or removed, depending on the administrator. Additionally, the names are used for convention: they are not required.

The file system’s tree begins at the slash (also known as “root directory”). This is indicated by a (/). The root directory contains all of the underlying files and directories inside the operating system.

A slash often precedes directories that are just one degree below the root directory. This symbol is used to indicate the position of those directories and differentiate them from other locations that may have a similar name. If you are using a new Linux system, you should check the root directory first. Here are the things that you’ll see:

The Subdirectories of a Root Directory

· /bin – This one contains ordinary programs, shared by the users, the system, and the system administrator.

· /dev – This subdirectory holds references to all the peripheral hardware of the CPU. In general, these pieces of hardware are indicated as files that have special characteristics.

· /boot – This is composed of the kernel (i.e. vmlinuz) and startup files. Some Linux systems also include the grub (i.e. grand unified boot loader) information. Grub is a piece of data designed to eliminate the various boot loaders being used today.

· /etc – This subdirectory contains files related to the system configuration. Basically, this is similar to the Control Panel of Windows computers.

· /home – This is the main directory for common users.

· /misc – This subdirectory is used for miscellaneous files.

· /lib – This one contains the library files for all types of computer programs installed in the computer.

· /opt – This location normally holds 3rd-party and extra programs.

· /root – This is the main directory of the system administrator.

· /proc – This is a virtual file array that contains data about the system’s resources. If you want to get more information about this subdirectory, you can open a terminal window and type in “man proc.”

· /initrd – This holds the data for booting processes. You should never remove this subdirectory.

· /lost+found – This subdirectory contains the files saved during system failures.

· /tmp – This is a temporary storage used by the operating system. Don’t use this for saving your work since it gets cleaned up during a system reboot.

· /sbin – This holds the computer programs used by the system administrator and the operating system itself.

· /usr – This contains the libraries, programs, and documentations, for user-related computer programs.

· /var – This is used to store variable and temporary files generated by users (e.g. mail queue, log files, file downloads, etc.).

You can use the “df” command followed by a dot (i.e. “.”) to identify the directory you are currently using. This command also shows the amount of storage used on that particular directory. Here’s a screenshot:

In general, each subdirectory belongs to the root partition, unless it possesses a different entry in the list generated by “df.”

The Shell

A shell can be considered as a language: you use it to “talk” to a computer. Most people know the other language, the point-then-click system being used in desktops. However, in that language, the machine is directing the conversation – the user assumes a passive role of choosing tasks from the presented ones. It is hard for a computer programmer to add all uses and possibilities of a certain command using the GUI-format. That’s why GUI-based systems are inferior to commands given from the backend.

A shell, however, is an advanced method of interacting with the machine, since it enables two-way conversations. Additionally, it allows the user to take the initiative. Both parties in the conversation are treated equally, so new concepts can be tried. Shells allow you to manage the system in a versatile way. As a bonus, shells allow you to automate tasks.

The Different Types of Shells

Here are the shells used by the Linux operating system:

· “sh” (also known as the Bourne Shell) – This is the shell originally used for Unix systems and Unix-related projects. Consider this as a basic shell: a small computer program that has limited features. When you are using a POSIX-compatible mode, Linux’s bash will mimic this shell.

· “bash” (also called the Bourne Again Shell) – This is the typical GNU shell: versatile and intuitive. Beginners are advised to use this, although advanced users can still use this as their main tool. When using Linux, bash is the default shell for ordinary users.

· “csh” (also known as C Shell) – Programmers use this shell since its syntax is similar to that of the C-programming language.

· “ksh” (also called the Korn shell) – People who are familiar with Unix systems appreciate this shell.

· “tcsh” (also known as Turbo C Shell) - This is a superset of the C Shell, boosting the system’s speed and user-friendliness.

If you want to see an overview of the shells used in Linux systems, you may check the file /etc/shells. Here’s a screenshot:

How to Switch to a Different Shell

To accomplish this, you just need to type in the name of your preferred shell in an active terminal. The operating system will use the PATH settings to find the location of the new shell. Because shells are considered as computer programs (i.e. executable files), the active shell will start and execute the new one.

How to Determine the Shell You Are Using

You can identify the active shell using these two methods:

· Access the directory /etc/passwd and see the line for your user account.

· Enter this command: echo $SHELL