Introduction to File System in Linux

Introduction to File System in Linux

A beginner's guide to complete understanding of the file system in Linux Environment

Linux storage management looks quite different for normal windows user. For example, the physical representation of the drive like the C:, D: or E: system in windows doesn't exist in Linux. Instead it uses a file tree structure with /(root) at the top and its many branches. A simplified version of how the tree structure looks is as belows

image.png

Most Linux distributions are organised to be consistent with the Filesystem Heirarchy Standard(FHS) Referencing those directories when accessing them is accomplished by using the sequentially deeper directory names connected by forward slashes (/) such as /var/log and /var/spool/mail. These are called paths.

(Linux does not use backslash("\") to seperate the componenets. Instead it uses the forward slash(/) as an alternative. For example, as in windows the data may be stored in C:\My Documents/Work whereas in Linux,it would be stored in home/My Documents/ Work)

The starting point of this heirarchal tree is called as root represented by the "/" character. It is called the home directory of the "superuser" ( also called as the "Administrator" of the system) It is seperate from the rest of the user's home directories (P.S- For my windows user friends, directory is the linux equivalent of a folder :) )

/(root) must contain all of the files required to boot the Linux system before other filesystems are mounted. It must include all of the required executables and libraries required to boot the remaining filesystems. After the system is booted, all other filesystems are mounted on standard, well-defined mount points as subdirectories of the root filesystem.

All the other sub-directories are discussed briefly as below

/bin/ :- contains basic programs and user executable files

/dev/ :- dev is short for device in linux and device inlinux is represented by its own file in the dev directory

/etc/ :- contains the configuration files like the names of the users on the system, their passwords, the names of machines on your network etc etc.

/usr/:-These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation. Notice that the user directory also contains sub-directories with the same name as root branches. In the original Unix implementations, /usr was where the home directories of the users were placed (that is to say, /usr/someone was then the directory now known as /home/someone). In current Unices, /usr is where user-land programs and data (as opposed to 'system land' programs and data) are. The name hasn't changed, but it's meaning has narrowed and lengthened from "everything user related" to "user usable programs and data".

/home/:- Home directory storage for user files. Each user has a subdirectory in /home.

/lib/ :- Contains shared library files that are required to boot the system. Libraries are files containing code that your applications can use. They contain snippets of code that applications use to draw windows on your desktop, control peripherals, or send files to your hard disk.

/sbin/:- It is short for system binary files. It is similar to /bin but it contains the applications only the root(superuser) will require. The reason /sbin exists is because linux discriminates between 'normal' executables and those used for system maintenance and/or administrative tasks. The latter reside either here or - the less important ones - in /usr/sbin

/tmp/ :- It contains temporary files which programs store when they are currently running. Many programs use this to create lock files and for temporary storage of data which they don't need right now, but may need later on. It is one of the few directories where any user can store data without having root privileges. However the files stored maybe delete at any time without prior notice (usually at boot )

/var/ :- It contains variable data handled by daemons(A daemon is a program/process that runs in the background ).This includes log files, queues, spools, and caches or other database files like MySQL, web server data files, email inboxes and much more. It has three main subdirectories namely log/, lock/ and tmp/ (There are other subdirectories as well but for simplicity, these three are the most common )

/var/log:- Log files from the system and various programs/services.Logs are files that register events that happen on the system. If something fails in the kernel, it will be logged in a file in /var/log; if someone tries to break into your computer from outside, your firewall will also log the attempt here.

/var/lock:- Many programs follow a convention to create a lock file in /var/lock to indicate that they are using a particular device or file. This directory holds those lock files (for some devices) and hopefully other programs will notice the lock file and won't attempt to use the device or file.

/var/tmp:- Temporary files saved between reboots. Files that need to exist for a longer time than what is allowed are stored here.Although the system administrator might not allow very old files in /var/tmp either.

This was all you needed to know to get started in understanding Linux and its file management. :)