History of Linux and Windows
Okay, before starting with the actual topic, let’s discuss what makes Linux different from windows. If you are a Windows user you might have seen different drives such as C, D, E, etc which are absent in Linux instead it has folders named /bin, /sbin, /usr, /etc.
For new Linux users, let us tell you about how Linux and windows evolved. Windows was installed on top of DOS(Disk operating system), which was a command-line tool where you can run programs, games, etc. It used letters to assign removable discs such as floppy drives, i.e. A and B. When the hard drive was introduced, the letter C was assigned for the internal disk and the next available letter for the next disk.
Microsoft evolved their kernel so that windows boots are less dependent on DOS and eventually without DOS at all. Linux follows the Unix tradition which is why it uses forward slash unlike backslash in windows. It is also case sensitive, also macOS has similar features as it is a common Unix-based ancestor.
So now let’s jump into the Linux filesystem.
A filesystem is used to control the flow of how data is stored or distributed or retrieved from a physical storage device such as HDD, SSD, etc. Its main purpose is to make users and the operating system store files in such a manner that all the different directories can utilize them efficiently.
The OS plays the role of intermediate that facilitates the data transfer for storage on a storage device. Linux uses a directory tree to manage directories and files. The tree information is also stored on a storage device and this part is called the root file system or root directory.
The root directory is the most important as all other directories are derived from it and it is responsible for booting, repairing, and restoring the Linux system.
The File hierarchy for Linux defines the Linux directory structure. We can refer to the sequential directories in those directories by using directory names connected by a forward slash (/) such as /var/log and /var/spool/mail. These are called paths.
Now let us explore these sub-directories of the root directory one by one.
/bin
This is a subdirectory of the root which stands for binaries and contains the executable programs, which are used for minimal functionality for booting or repairing. It usually contains the shell commands like cp(copy), rm(remove), ls, etc. It also contains programs that boot scripts may depend on. Bin folders can also be found in other sections of the file system tree.
/sbin
This stands for system binaries that a system administrator may use and a standard user would not have access without permission. This folder, along with the one above it,contains the files that must be accessible while running in single-user mode (this mode boots you in as a root user to enable you to perform device repairs,updates, and testing) rather than multi-user mode.
/boot
This directory contains all the executables or programs responsible for booting up a Linux machine whether it is ubuntu or kali or mint. As a result, the data used until even the Linux kernel starts to run some program is stored in the /boot directory.
/dev
This directory houses some exclusive or device-specific files. Everything in Linux is categorized as a file or a directory, as this command emphasizes.
$ ls -la /dev
We can see all the partitions on the system. /dev/cdrom represents our CD-ROM. Here the nested files represent a hardware device and any changes to them will be reflected in our hardware. For example, /dev/dsp represents the speakers and if you make changes to it, it will be reflected in the speakers. For instance, it will make a sound if you cat something on it.
$ cat /boot/vminux > /dev/dsp
/etc
This directory contains all your configurations. Here configuration refers to those which are system-wide and not just for a particular user such as /etc/apt contains the sources list which contains the repo’s the system connects to and its various settings.
/lib, /lib32, /lib64
These are the directories where the libraries are stored. Libraries are files that the application uses to perform various functions, and these are required by the binaries in the /bin directory.
/media and /mnt (mount)
These are the directories where we can find our other mounted drives such as USB,floppy disks, or external hard drives, etc. The /media folder wasn’t there before.
It was just /mnt, but nowadays most Linux distros automatically mount devices in /media directory. But why two directories for mounting? Well, When manually mounting files, we use the /mnt directory and leave the /media directory to the operating system.
/opt (this is the optional folder)
This folder usually contains manually installed software from any third-party vendors. This is the place where you can install the software created by you.
/proc
This directory contains all the pseudo files that have information about the system processes and resources. Every process has a directory (named after the process ID) that contains all the necessary information on that process and these are not saved on the hard drive. The files here are translated by the kernel to generate some other information. for example
$ cat /proc/cpuinfo
This command prints out the information about the CPU.
/root
This is the home directory of the root user. It does not contain typical directories and does not reside in the /home directory, unlike a user's /home directory. You can store the files here but you need to have root access. This directory's location also means that the root has constant access to its /home folder.
/run
This directory is relatively new, and various distributions use it in different ways. It's a tempfs file system, which means everything in it is deleted when the system is rebooted or shut down. It is used to store runtime information that processes use to work early in
the boot method.
/srv
This is called a service directory where data from the service is saved. For you, it will most likely be null, but if you run a web server or an FTP server, you will store files here that will be accessed by other users. Since it is at the root of the drive, it provides better
protection.
/sys
This is called a system directory, It's been around for quite some time. It's a method of communicating with the kernel. This directory is similar to the /run directory in that it is not written to the disc physically. It's generated every time the machine starts up, so you wouldn't save anything here, and nothing is mounted here.
/tmp
It is a temp (temporary) directory. This is where the program temporarily stores files that could be used during a session. For example, when you write a document in a program in vscode, it will save a temporary copy of what you're writing here on a regular basis. If the program crashes, you can search here to see if you have a recently saved copy that you can restore.
When you reboot your computer, this folder is normally empty. Any files or directories may still be present or may have been stuck because the machine was unable to remove them. This isn't a concern unless there are hundreds of files taking up disc space, in which case you'll need to log in as root and manually delete them.
/usr
In contrast to the /bin directory, which is used by the system and system administrator to perform maintenance, this is the user application space where programs that are used by the user will be installed. Any program installed here is considered non-essential for basic system service, and it is also known as Unix System Resource.
The installed programme can be found in a variety of locations, including /usr/bin, /usr/sbin, and /usr/local. The local directory is where most programs installed from source code end up. The /usr/share is where many larger programs mount themselves.
/var
This is the directory for variables. It contains files and directories that are expected to grow in size over time, such as dynamic data. /var/log contains system and application log files, which will grow in size as you use the system. Other items included here include mail databases and temporary storage for printer queues, also known as /spool.
/home
Each user has this directory. The /home directory is where you store your file and documents. Each user can access only their folder unless admin permissions.
Conclusion
And, phew...! finally we have reach the end. In this article, we have covered all the different Linux File system directories. We have also seen what makes Linux FS different from Windows FS and how Linux evolved. I certainly hope that you now have knowledge of what each directory in Linux FS means and its true functionality as well as its role in OS.
Top comments (0)