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
/home Contains the user’s home directories along with directories for services
ftp
HTTP
samba 
/bin Commands needed during bootup that might be needed by normal users
/sbin Like bin but commands are not intended for normal users. Commands run by LINUX.
/proc This 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.
/usr Contains all commands, libraries, man pages, games and static files for normal operation.
bin Almost all user commands. some commands are in /bin or /usr/local/bin.
sbin System admin commands not needed on the root filesystem. e.g., most server programs.
include Header files for the C programming language. Should be below /user/lib for consistency.
lib Unchanging data files for programs and subsystems
local The place for locally installed software and other files.
man For manual pages
info  For Info documents
doc For Documentation
/boot Files used by the bootstrap loader, LILO. Kernel images are often kept here.
/lib Shared libraries needed by the programs on the root filesystem
modules Loadable kernel modules, especially those needed to boot the system after
disasters.
/dev Stored Device files
/etc Configuration files specific to the machine.
skel When a home directory is created it is initialized with files from this directory
sysconfig Files that configure the linux system for devices.
/var Contains files that change for mail, news, printers log files, man pages, temp files
lib Files that change while the system is running normally
local Variable data for programs installed in /usr/local.
lock Lock files. Used by a program to indicate it is using a particular device or file
log Log files from programs such as login and syslog which logs all logins and
logouts.
run Files that contain information about the system that is valid until the system is
 next booted
spool Directories for mail, printer spools, news and other spooled work.
tmp Temporary files that are large or need to exist for longer than they should in /tmp.
catman A cache for man pages that are formatted on demand
/mnt Mount points for temporary mounts by the system administrator.
/tmp Temporary 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 Type Description
Regular files These files are similar to those used by the file systems of other operating systems—for example, executable files, OpenOffice.org files, images, text configuration files, etc.
Links These files are pointers that point to other files in the file system.
FIFOs 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 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.

Leave a Reply

Your email address will not be published. Required fields are marked *