MODULE 1.3 – LINUX FILE SYSTEM STRUCTURE

This tutorial will absolutely make you understand the Linux file system structure.

Structure Of Linux

Linux file system
Linux Directory Structure

The structure (chart) above depicts the Linux File system hierarchy.

Log in to your Personal Server or the cloud server, for now, enter the commands below (Our next module will be on basic Linux commands and type of users in Linux)

# cd /


# ls

For the ones logging into the cloud server, the public IP of the Cloud server is 51.144.115.34. Enter the username and the password sent to your email (I already mentioned how to connect in the previous module).

Moving forward, One Important thing one need to always remember is that everything in Linux is considered to be a file. I mean everything. The reason why you hear every frequent Linux users always say, “In Linux, everything is a file”.

Linux file-system structure is hierarchical, all files are stored on the disk under one main directory, / (root). The directory has been further subdivided into directories like /usr, /var, /mnt, /boot, etc. as shown in the structure above.

These directories have been organized to store a specific type of file. You will get to understand better how these directories and structure work and all these will begin to make a lot of sense as you begin to use the Linux OS often. Everything we are going to be doing will be in these directories.

These directories are the whole system. If you remember, during our installation, I mentioned that we should set the destination installation to “automatic partitioning”. If we had done manual, you may not have understood except you are familiar with Linux already. But in the real world, you won’t be doing automatic partitioning but manual. We will, of course, do the manual installation in our next installation when we are certain we have understood the structure as we proceed. 

These directories are explained below.

Linux File System, Directory Structure Explained

/root

This is the root user’s home directory. Every file and directory starts from this directory. Though, this directory is root’s home directory, it doesn’t live in /home directory, so other users can also store data in this directory provided they have the necessary permission.

/bin

This directory stores many utilities of Linux. When I say utilities, I mean programs or applications. They are executable files. These utilities are commands available under the Linux system. i.e basically used for the Linux system functions. Examples are ls, cp, cat, etc. They are in binary format, hence named “bin”

Basically, other applications installed in Linux are not usually installed in this directory because this directory contains programs that are used for maintenance tasks when the system is booted into single user mode, and in single user mode, some functions, especially network are meant to be disabled because of security reasons, hence why other applications will not be installed here so as not to cause security bridges.

/dev

This directory stores all the device-related files for the system. examples are the block devices, disks, cdrom, partitions like sda, sda1, sda2, etc.

/mnt

This directory can be used as a directory where users can temporarily mount file-systems. 

/etc

system-related data and configuration files required by programs are all stored here. For example, passwd (/etc/passwd), yum, logrotate, etc. These configuration files are all system related. The configuration file stored here affects all users. However, the configuration files that are not system related may not necessarily be stored here, it can also be stored in the user’s home directory depending on the program.

· /proc

This can also be called a virtual file system. It contains real-time information about the processes running on the system. It presents this information as a file/directory. Remember, I mentioned earlier that everything is a file in Linux.

For example, the current cpu information, memory information and partition information can be gotten in this directory.

To get the current memory info, use the command,

[root@RHEL proc]# cat /proc/meminfo

MemTotal:        1849532 kB
MemFree:          183436 kB
MemAvailable:     508184 kB
Buffers:               8 kB
Cached:           428764 kB
SwapCached:         9364 kB
Active:           546704 kB
Inactive:         567864 kB
Active(anon):     323764 kB
Inactive(anon):   367344 kB
Active(file):     222940 kB
Inactive(file):   200520 kB

To get the current cpu info, use the command

 253        1    1572864 dm-1
[root@RHEL proc]# cat /proc/cpuinfo

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model   : 69
model name      : Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz
stepping        : 1
microcode       : 0x24
cpu MHz         : 2501.000
cache size      : 3072 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level     : 13

To get the current partition info, use the command,

[root@RHEL ~]# cat /proc/partitions

major minor  #blocks  name

   8        0   15728640 sda
   8        1    1048576 sda1
   8        2   14679040 sda2
  11        0    7667712 sr0
 253        0   13103104 dm-0
 253        1    1572864 dm-1

· /boot

This directory stores all the necessary files that is needed to boot the system including the boot loader and the system kernel.

· /home

This directory contains all the home directory of users. It’s the directory where users store personal files like photos, music, documents, desktop, videos, etc. [e.g. /home/victor]. Every user can only access their home directory only except the required permission is given to access other user’s home directory.

· /lib

This directory contains libraries of data for the compilers installed on the system, such as the C language routine. In other words, these files are helpful and used by an application or a utility or a process to perform various functions for their proper execution.

· /lib64

This directory is similar to /lib. The difference between this directory and /lib is the architecture level differences. It stores 64-bit library files.

· /usr

Unix system resource (usr) stores the OS files which are not involved in the boot process. applications and files that are used by users and not the system are also stored in this directory. i.e, it contains all the user’s system resources like user’s binaries, libraries, header files, etc. For example, Many and more utilities that are not in /bin are available in the “/usr/bin” and “/usr/sbin” directory, they are considered non-essential to the system as opposed to the /bin or /sbin directory where essential programs/utilities and files needed by the OS are stored.

The /usr also contains shared files. i.e. /usr is shareable. This directory also contains more of libraries and data files used by various Linux commands. [i.e./usr/lib], the /usr/tmp stores more temporary files. This directory is read-only.

· /sbin

This directory is analogous to /bin. The difference is that it stores the binaries (programs/applications) intended to be used for system maintenance and administrative tasks by system administrators or root/super users only. No other users will have access to these applications except the required permission is given. Utilities like init, fdisk, swapon, lvm, lvremove, lvrename, vgs, vgcreate, vgremove, etc are stored in this directory. These programs are in binary format, hence “/sbin” (system binary).

Just I mentioned when explaining /bin, basically, other applications installed in Linux are not usually installed in this directory because this directory contains programs that are used for maintenance tasks when the system is booted into single user mode, and in single user mode, some functions, especially network are meant to be disabled because of security reasons, hence why other applications will not be installed here so as not to cause security bridges.

· /opt

This directory is reserved or stores optional packages. i.e. packages that are not part of the default application. Most times, third party applications are always installed in this directory and applications that don’t follow the UNIX file hierarchy standard also dumps its file in this directory.

· /sys

There is now an addition of a virtual files-system to the kernel which is /sys. This directory helps to clean up / proc as much hardware related information has been moved to /sys. It tends to be more organized compared to /proc

· /media

This directory creates a sub-directory or a mount point for a removable media when it’s inserted into the system. It automatically mounts the media depending on the variant or can be used as a temporary mount point for a media where contents can be easily accessed. E.g. CD, USB, etc.

This directory is similar to /mnt. The difference is that, in /mnt, mount points are manually mounted while in /media, mount points are automatically mounted. This as well depends on the Linux distribution.

· /lost+found

This directory contains recovered corrupt files. If a system didn’t go through a proper shutdown and a file-system crashes, the files-systems will be checked when the system is booting up and dumps every recovered corrupt file in this directory. 

· /var

variable directory, (/var) stores variable data. i.e. files and directories that the system writes to during operation and grow in size. It’s the opposite of /usr. /usr is a read-only, all the operations that is supposed to write to /usr, for example, log files are written in /var.

· /srv

srv means “service”. The services that are provided by the system, for example, Apache web server’s data, FTP data, etc. are stored in this directory. The data file for a particular service can easily be located in this directory.

· /tmp

This directory stores temporary files created by the OS or other applications as they function. Users can also store temporary files in this directory. Most times, files in this directory are deleted automatically when the system is restarted. If you want to delete a file in this directory, be sure of what you are doing because the files in this directory contain temporarily what the system, processes, etc. currently uses to function. 

As we go on, we begin to understand more about filesystems structur by persistent use of the Linux operating system.

Class Activity 1.3: What does the /run directory contain?

 Cheers!!!

NEXT MODULE: BASIC LINUX COMMAND

Be the first to comment

Leave a Reply

Your email address will not be published.


*