Skip to content

Linux File System

In the Linux file system, files are grouped according to purpose. Ex: commands, data files, documentation. Several major directories are associated with all modern Unix/Linux operating systems. These directories organize user files, drivers, kernels, logs, programs, utilities, and more into different categories. The standardization of the FHS [Filesystem Hierarchy Standard] makes it easier for users of other Unix-based operating systems to understand the basics of Linux.

Every FHS starts with the root directory, also known by its label, the single forward-slash (/). All of the other directories shown in the Table are subdirectories of the root directory. Unless they are mounted separately, you can also find their files on the same partition as the root directory.

root(/) The home directory for the root user
/homeContains the user’s home directories along with directories for services
/binCommands needed during bootup that might be needed by normal users
/sbinLike bin but commands are not intended for normal users. Commands run by LINUX.
/procThis filesystem is not on a disk. It is a virtual filesystem that exists in the kernels
imagination which is memory.  A directory with info about process number  and each process has a directory under proc.
/usrContains all commands, libraries, man pages, games and static files for normal operation.
Almost all user commands. some commands are in /bin or /usr/local/bin.
System admin commands not needed on the root filesystem. e.g., most server programs.
Header files for the C programming language. Should be below /user/lib for consistency.
Unchanging data files for programs and subsystems
The place for locally installed software and other files.
For manual pages
For Info documents
For Documentation
/bootFiles used by the bootstrap loader, LILO. Kernel images are often kept here.
/libShared libraries needed by the programs on the root filesystem
Loadable kernel modules, especially those needed to boot the system after
/devStored Device files
/etcConfiguration files specific to the machine.
When a home directory is created it is initialized with files from this directory
Files that configure the linux system for devices.
/varContains files that change for mail, news, printers log files, man pages, temp files
Files that change while the system is running normally
Variable data for programs installed in /usr/local.
Lock files. Used by a program to indicate it is using a particular device or file
Log files from programs such as login and syslog which logs all logins and
Files that contain information about the system that is valid until the system is
 next booted
Directories for mail, printer spools, news and other spooled work.
Temporary files that are large or need to exist for longer than they should in /tmp.
A cache for man pages that are formatted on demand
/mntMount points for temporary mounts by the system administrator.
/tmpTemporary files. Programs running after bootup should use /var/tmp.

Types of Files Used by Linux

When working with Linux, you need to be aware of the fact that there are a number of different file types used by the file system. This is another area where the Linux file system differs significantly from the Windows file system. In Linux, there are a variety of different file types used by the file system. These include the file types shown in Table:

File TypeDescription
Regular files
These files are similar to those used by the file systems of other operating systems—for example, executable files, files, images, text configuration files, etc.
These files are pointers that point to other files in the file system.
FIFO stands for First In First Out. These are special files used to move data from one running process on the system to another. A FIFO file is basically a queue where the first chunk of data added to the queue is the first chunk of data removed from the queue. Data can only move in one direction through a FIFO.
Sockets are similar to FIFOs in that they are used to transfer information between sockets. With a socket, however, data can move bidirectionally.

The Linux File system in reality

For most users and for most common system administration tasks, it is enough to accept that files and directories are ordered in a tree-like structure. The computer, however, doesn’t understand a thing about trees or tree structures.

Every partition has its own file system. By imagining all those file systems together, we can form an idea of the tree structure of the entire system, but it is not as simple as that. In a file system, a file is represented by an inode, a kind of serial number containing information about the actual data that makes up the file: to whom this file belongs, and where is it located on the hard disk.

Every partition has its own set of inodes; throughout a system with multiple partitions, files with the same inode number can exist.

Each inode describes a data structure on the hard disk, storing the properties of a file, including the physical location of the file data. When a hard disk is initialized to accept data storage, usually during the initial system installation process or when adding extra disks to an existing system, a fixed number of inodes per partition is created. This number will be the maximum amount of files, of all types (including directories, special files, links, etc.) that can exist at the same time on the partition. We typically count on having 1 inode per 2 to 8 kilobytes of storage.

At the time a new file is created, it gets a free inode. In that inode is the following information:

  • Owner and group owner of the file.
  • File type (regular, directory, …)
  • Permissions on the file
  • Date and time of creation, last read, and change.
  • Date and time this information has been changed in the inode.
  • A number of links to this file (see later in this chapter).
  • File size
  • An address defining the actual location of the file data.

The only information not included in an inode is the file name and directory. These are stored in the special directory files. By comparing file names and inode numbers, the system can make up a tree structure that the user understands. Users can display inode numbers using the -i option to ls. The inodes have their own separate space on the disk.
$ ls -il
total 1
639036 -rw-r–r–    1 Anil     Administ       24 Mar  1 20:12 file1.txt
2044316 -rw-r–r–    1 Anil     Administ       24 Mar  1 21:26 file2.txt
You can see the inode number of files [file1.txt & file2.txt] highlighted in Red.

You may want to see
How to sort contents of a file

The sort command is used to sort the contents of a file. You can sort the data in a text Read more

How to use sed command in Linux

sed, short for "stream editor", allows you to filter and transform text. A stream editor is used to perform basic Read more

How to use crontab in Linux

Cron is the system process that will automatically perform tasks for you according to a set schedule. The schedule is Read more

How to extract archive file in Linux

To extract archive file in Linux, you can use the tar command, used for extracting content from the archive files. "tar" Read more

Leave a Reply

Your email address will not be published.