In this article who are going to learn what is a file system and how the Directory structure (Filesystem structure) organized in Linux. The file system is a method and data structure that an operating system uses to keep track of files on a disk or a partition. This is the way the data organized on the disk. Before a partition or disk is used to the filesystem it has to initialized so this process called making a filesystem.
Linux supports different types of filesystems. Like
- ext2
- ext3
- ext4
- JFS
- ReiserFS
- XFS and etc.
so each filesystem has its own advantage(we are not talking about an individual) which makes them special. But EXT4 (extended filesystem) is very popular among all the other filesystems. Before this, we had ext2, ext3. Ext4 is added performance and additional features which makes it very popular, stable, and speed access to files on disk. And we can mount the ext3 FS also since it supports old versions. Several other features like multiblock allocation, delayed allocation, journal checksum, fast fsck, etc. we can turn off the journaling feature if we want.
Linux Directory Structure (File system Structure)
Let’s talk about the Linux FS structure. unlike Windows, the Linux FS structure is a little bit different. we don’t have any volumes like A, B, C… In Linux, the FS structure is in a single directory Tree. the starting point starts from the root(/). if you want to use any filesystem you have to mount the FS. The below picture can help you to understand how the FS structure organized.
so let’s talk about each directory. have you ever thought why do we have a different location to keep the program files(commands). Like few commands are in /bin , /sbin, /usr/bin, /usr/bin. today we will discuss that. Most people who have used the Linux seen the root directory but not everyone familiar with other directories and for what they are used.
“/” (top directory ion hierarchy/root directory): this is the place everywhere every single file and directory starts. only the root privileged user has access to this directory. Don’t confuse to “/” and “/root”. / is root directory and /root is home for the root user.
/root: This is the root user’s home folder. unlike other users, the home directory for the root will not create in /home location. In the /root directory you can save the files but for that, you need root privileges.
/bin: This is the binaries folder. It contains binary executables. All the commands which are under this directory can use by all the standard users. commands are like ps, ls, ping, grep, etc
/sbin: It is a System Binaries. It is also the same as the bin, it has the binary executables. But the commands mostly used by system administrators for system maintenance and troubleshooting purpose. you need special permission to access these files the standard user doesn’t have access to these commands. Commands are like mkfs, reboot, IP, IPtables
/etc: This is the “et cetera” folder created to store all extra files. But it becomes a heart for all the configuration files. That said it is the place where you see all configuration related files. if you want to change any default behavior of any tool or script(start/stop, and etc), this is the place where you spend most of the time. like host.conf, resolv.conf
/dev: In this folder, we have all the information on the device files. In Linux, everything treats as a file or directory. if you look at the /dev location you can see sda, sda1,sda2(or hda) these all are the partitions in your system and another example “psaux” which is a mouse connector.
/proc: It is a pseudo file system, This is a very special place where you can see the information about the system process. It doesn’t contain the real files but runtime system information(system memory, device mounted, hardware configuration). And it also creates a new directory inside the /proc every time with the PID no when you start a new process. this folder will have all the information like execution command, status, and other system call details of that specific process. So it is the best place to explore about Linux system, including its kernel, processes, and configuration parameters.
/boot: This is the folder you really don’t want to play around unless you know exactly what you are doing. This folder has everything that your system needs to boot. in other words the boot loader lives here.
/lib: This folder contains all the libraries. these are the various files the system can use while performing tasks. It supports the binaries under /bin and /sbin. the file names typically start with ld* or lib*
/mnt: We call it Mount. In this directory, you can find all the mounted devices like USB, external HDD, floppy disk, etc
/Media: This is the new folder to keep temporary files like USB, floppy drives. This is just like /mnt. you mount the devices to /mnt and the devices automatically showed up to /media. In this directory, the removable disks will be /Media/Userdevicename hierarchy.
/opt: this optional folder. this is the place where third party apps reside. means if you install any app like chrome, all the related packages and files will be a store here. while installing the package manager will find this place to store the files.
/usr: Most of the people thing USR means User but the actual meaning is “Universal System Resources”. Back in Linux days, the USR folder is users’ home directory like /usr/someusername/theirfolder but later the user home directory moved to /home folder. the usr folder contains all the user binaries, Documentation, libraries, header files and etc. The name hasn’t changed but USR land changed from “everything user related” to “user usable program and data”. So now the people referring to this as “User System Resources”.
/usr/bin contains the binary files for user programs. if you didn’t find a system binaries under /bin then this is the place where you need to look. Ex: Mount, mv, systemctl
/usr/sbin this is the same as above if you didn’t find a system administration related binaries under /sbin then this is the place where you need to look. Ex: sshd, useradd, userdel
/home: The home directory for all the users will have all the user folders/private information like desktop, downloads, documents, etc. the folders create like /home/user1, /home/user2
/temp: It is a folder for temp files that are created by system and user. these files will be deleted once the system rebooted. It used to store run time information.
/var: Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files.Some portions of /var are not shareable between different systems. For instance, /var/log, /var/lock, and /var/run. Other portions may be shared, notably /var/mail, /var/cache/man, /var/cache/fonts, and /var/spool/news
/srv: Srv stand for service. it contains all the server-specific related data.
To understand more about the filesystem please start to play around it and look at the different folders and binary files it will more idea.
Thank you for reading. Happy learning. Please subscriber for more updates.