People new to Linux frequently ask what all of these directories in the Linux filesystem mean.
This array of directories can be intimidating if you’re expecting a c drive like in Windows Operating systems.
Unix and Linux Filesystems display files, configuration, and system information in a folder hierarchy. Understanding how these files and folders interact is a critical component of becoming acquainted with a Linux server.
Almost every Linux administrator will spend some time in these files. So let’s start with the fundamentals of the Linux Filesystem.
If you are familiar with Windows, the equivalent of a directory in Linux is called a folder.
Linux directories can be accessed either through the command line or a graphical user interface.
If you are comfortable with command lines, you can use the command ls to list the contents of a directory.
For example, if you want to view the contents of the /home/user directory on your Linux server, you would type:
If you want to view the contents of the /home/user directory as a tree, you can use the command ls -R.
The ls command is the most used command in Linux. It is quite useful for listing files and system info in a directory.
The / is the root of the filesystem. It is like the beginning. You can try it yourself by typing ls / in your terminal. After you hit on enter, you’ll see the directories we’ll be learning about.
I should point out that these folder descriptions are standard in most Linux systems, but they are not usually rigidly followed. Some Linux flavors vary it slightly.
The Linux Filesystem Explained: How Each Directory is Used?
This section explains how each directory is used, what it is used for, and what happens if you delete it? When you first log into your computer, you may notice that your home directory is highlighted. This is because your home directory contains your personal files, and is the default location for programs to store user-specific data.
We will cover all of the major types of directories that exist on a Linux system in this article.
The bin is a directory in current Linux editions that contains critical executable programs and core operating system instructions. This directory is often symbolically connected to /user and /bin, which we’ll discuss. Listing out this folder reveals a plethora of programs. We use it every day, even the ls command itself is in the bin folder.
Unsurprisingly, boot is the directory containing the files required by the bootloader. The kernel and the basic ram file system are also located here. The system uses the boot directory for boot and other important start-up files. Unless you know what you’re doing, you shouldn’t be messing with the boot folder in a Linux FileSystem.
Your device files are stored in dev. These files are generated dynamically based on your system’s many physical and virtual devices.
You may have heard the statement everything in Linux is a file or directory. The /dev does a good job of demonstrating this on my Linux desktop.
For example, if you do ls -l, / dev/sd*. You can see some basic information about your hard drive.
As you can see, files and directories in the dev directory provide crucial information regarding your sd drive partitions.
What’s connected to your system, and how do we utilize this information to operate our servers?
The etc directory is where you’ll find your crucial configuration files and startup scripts.
When you administer a Linux server, you spend a lot of time in this directory. If I want to update my server’s ssh settings, I’ll modify the file located at /etc/ssh/sshd_config.
The pronunciation of this directory varies from person to person. I’ve always called it at c, and that’s how I hear it referenced a lot of the time, but others might call it, e t c or etc. Ultimately, there is no right or wrong answer, as everyone will have their own unique way of pronouncing this word.
The home directory is the location of each user’s home directory. If you’re used to working in Windows, you may be familiar with my documents directory; this is a similar directory in the Linux world.
Normally, each regular user on your machine is assigned a directory within the home folder. The contents of another user’s home directory are not visible to a regular user.
When you open a Linux terminal, the directory you start in is often your home directory. That’s what the small tilde in the prompt means. It’s worth noting that the home directory also contains user-specific setup files.
For example, I can see my bash profile configuration here, and the lib directories contain the shared libraries. Your system’s programs will require these shared libraries, which allow numerous programs to share code, resulting in increased efficiency.
Depending on your operating system, you may have a few directories that begin with lib lib32, and lib64 are typical, referring to libraries for 32-bit and 64-bit programs, respectively.
Again, different systems handle this differently. As previously stated, flexibility is your friend, and like the bin directory, odds are it will be symbolically connected to the user this time? /lib directory
After a system crash, pieces of broken files may remain in the lost+found directory. In general, we don’t want to place files there on purpose.
The media directory is the mount point for file systems stored on portable media. When you plug a flash drive into your computer and perform the command ls /media/user1, user1, being your login on the system, You should get a listing of the flash drive files.
When your Linux system automatically mounts a device, such as a USB drive, this is where you’ll find it. The mount or mnt directory is where you’ll temporarily mount devices, such as if you wish to attach a network storage server to archive some files temporarily.
This is normally where it will be mounted. It should be noted that, while the goal is for this to be a transitory location, some systems do permanently mount stuff here.
The opt directory is rarely used, but it isn’t completely gone. Optional software packages are typically placed in this directory by vendors. OPT is generally kept around for compatibility when you add on to your system, but it’s not completely gone.
A good example of a pseudo-file system is the proc directory. A faux file system is a file system that is established during startup and then deleted when the computer is shut down.
The proc sudo Linux filesystem stores information on every process currently operating on your machine. In reality, each running process has its subdirectory in this directory.
It also includes a wealth of information about your system. For example, I can view my CPU information with cat /proc/cpu info.
The root user’s home directory is the /root directory. This is the user with the most power on most modern Linux systems. Typical users cannot read the contents of this directory unless they use sudo or switch to the root user run.
Like the proc directory, the run directory includes information about your system since startup time, such as who is logged in and what demons are operating. The information in the run directory may be important as you collect information about your system and its use.
The sbin directory, like the bin directory, includes system-critical files. Historically, sbin applications were statically linked and so had fewer library requirements.
However, this convention is no longer applicable in modern systems. There isn’t much of a practical distinction between bin and sbin.
Like the bin directory on recent Linux, sbin is frequently symbolically linked to /user/bin.
The srv directory is occasionally used as a folder for files delivered by a web server or other server method such as FTP, but this is not universally accepted and, honestly, is rarely utilized in the present day in my experience. However, you’ll merely see this as an empty directory most of the time.
The sys directory contains information on your system’s devices, drivers, and kernel features. This directory is frequently referred to as “like proc, but better structured,” and I can see why.
As a Linux administrator, you’ll regularly utilize sys and proc to retrieve information about your working systems.
The temp directory is exactly what it sounds like: a location for temporary files. This directory is frequently used to store items. We don’t intend to keep it past the next reboot. There are various files you might put here, such as temporary items, downloading keys, or even just as a terminal scratchpad on the fly.
The usr or usr folder contains most of the programs and utilities your system will be running now.
People frequently pronounce this directory as user, which sounds like a user directory or a directory of users, but that’s not an appropriate description of the usr directory.
It’s preferable to think of it as the location of the majority of your programs. Do you remember the /bin folder? The /bin is simply a link to the usr’s folder.
A file placed in the /bin is placed in the usr’s /bin and is only visible in the /bin for compatibility considerations; the same is true for the /s-bin.
On most current Linuxes, it’s merely a link to usr/sbin. Because most of your programs are stored here, your lib folders will normally be symbolically linked here as well. It is typically shared by all users and read-only unless accessed via root or sudo.
the var directory contains system-specific variable files. This includes logs, temporary messages, files, and spool files, among other things.
You may discover configuration files that aren’t in etc here on occasion, and this is also where web servers are stored. The web server Apache, for example, frequently serves items from the var www directory in var.
The Linux filesystem has a lot of functionality, but the basics are the same as on other operating systems. This article explained the most basic concepts of how directories and files are organized in a Linux filesystem. Most Linux operating systems use the same structure to organize files in the Linux Filesystem.