The Linux File System Structure Explained

Datetime:2016-08-23 03:16:10          Topic:          Share

When I was first coming from Windows and exploringLinux, I found the  Linux filesystem structure to be a bit confusing, simply because I didn’t know anything other than the Windows file system for my entire life. But after persisting through the learning curve, the mystery was unraveled and I can now comfortably switch between Linux and Windows whenever needed, and I actually feel like I understand the Windows file system better now after learning the Linux file system.

For me, the biggest difference between the two file systems is to understand where the root of the file system begins. In Windows, the root begins at the drive letter, usually C:\, which basically means it begins at the hard drive. In Linux however, the root of the filesystem doesn’t correspond with a physical device or location, it’s a logical location of simply “/”. See the graphics below for a visual representation.

​Linux File System Structure Tree

Image Courtesy - tldp.org

​Windows File System Tree

Another thing to remember is that in Linux, everything is a file. Or, more accurately, everything is represented as being a file, while in Windows it may be displayed as being a disk drive.

For example, in Windows the hard drive is typically represented as C:\ in the file explorer, and it will even display a little icon of the hard drive and display how much space is being used. In Linux, on the other hand, the hard drive as represented merely as /dev/sda, which is really just a folder/directory, which in Linux is really just a file that points to other files.

So let’s take some other more practical examples. The Linux equivalent of your Documents folder in Windows would be /home/username/Documents, whereas in Windows it’s typically C:\Users\UserName\Documents. These are actually pretty similar, but you can see where the differences lie.

So using the above Linux file system chart, we need to explore what each folder in the Linux file system is for, which will help us to better understand how Linux works in general. Note that not every folder listed here or pictured above necessarily appears in every Linux distro, but most of them do.

  • /  - this is known as “root”, the logical beginning of the Linux file system structure. Every single file path in Linux begins from root in one way or another.  /  contains the entirety of your operating system.
  • /bin  - Pronounced “bin” (as opposed to “bine”), this is where most of your binary files are stored, typically for the Linux terminal commands and core utilities, such as cd (change directory), pwd (print working directory), mv (move), and so on.
  • /boot  - This is where all the needed files for Linux to boot are kept. Many people, including myself, like to keep this folder in it’s own separate partition on the hard drive, especially when dual-booting is involved. A key thing to note is that even when  /boot  is stored on different partition, it is still  logically  located at /boot as far as Linux is concerned.
  • /dev  - This is where your physical devices are mounted, such as your hard drives, USB drives, optical drives, and so on. We’ve already explored that typically, your system hard drive is mounted under /dev/sda, whereas your USB thumb drive might be mounted under /dev/sde. You may also have different partitions on your disk, so you’ll see /dev/sda1, /dev/sda2, and so on. In Windows, when you go to “My Computer” or “Computer” and you can see all of the physical devices and drives connected to your computer, this is the equivalent of /dev in  Linux file structure .
  • /etc  - Pronounced “et-see”, although some also prefer to spell it out, is where configuration files are stored. Configurations stored in /etc will typically affect all users on the system; whereas users can also store configuration files under their own /home folders, which will only affect that particular user.
  • /home  - This is where you’ll spend the overwhelming majority of your time, as this is where all of your personal files are kept. The Desktop, Documents, Downloads, Photos, and Videos folders are all stored under the /home/username directory. You can also store files directly in your /home folder without going to a sub-folder, if you wish so. Typically, when you open a command-line terminal in Linux, the default location that the terminal points to is your  /home/username  folder, unless you’ve manually changed the default location to something else.
  • /lib  - This is where libraries are kept. You’ll notice that many times when installing Linux software packages, additional libraries are also automatically downloaded, and they almost always start with lib-something. These are basically the files needed for your programs on Linux to work. You can think of this folder as somewhat equivalent to the Program Files folder on Windows, although it’s not exactly the same. Unlike Windows, libraries can be shared between many different programs, which results in Linux installations typically being much more lightweight than Windows, because typically in Windows each program needs it’s own library installed, even if it’s redundant and already exists for another program. Surely a benefit of Linux file system structure.
  • /media  - Another place where external devices such as optical drives and USB drives can be mounted. This varies between different Linux distros.
  • /mnt  - This is basically a placeholder folder used for mounting other folders or drives. Typically this is used for Network locations, but you could really use it for anything you want. I used to use it as the mount point for my media server’s hard drive (/mnt/server).
  • /opt  - Optional software for your system that is not already managed by your distro’s package manager. I don’t really ever find myself using this, your mileage may vary.
  • /proc  - The “processes” folder where a lot of system information is represented as files (remember, everything is a file). It basically provides a way for the Linux kernel (the core of the operating system) to send and receive information from various processes running in the Linux environment.
  • /root  - This is the equivalent to the /home folder specifically for the root user, also called the superuser. You really don’t want to touch anything in here  unless you know what you’re doing .
  • /sbin  - Similar to /bin, except that it’s dedicated to certain commands that can only be run by the root user, or the superuser.
  • /tmp  - This is where temporary files are stored, and they are usually deleted upon shutdown, which saves you from having to manually delete them like is required in Windows.
  • /usr  - Contains files and utilities that are shared between users.
  • /var  - This is where variable data is kept, usually system logs but can also include other types of data as well.

You can do some more research online and go deeper to learn more about specific applications and usage of each of the above mentioned folders, but for the typical everyday home user, your /home folder is generally the only folder you’ll be directly interacting with. Occasionally you may have to venture into the other folders if you’re trying to do some troubleshooting, but typically modern Linux distros automatically maintain these folders and they require little to no user interference. The exception would be if you’re using a distro like Arch Linux or Gentoo, in which case, you probably didn’t need to read this article in the first place.

Conclusion

To reiterate my previous statement, keep in mind that the Linux file system is a  logical system, rather than a physical one. Different folders in the system may be on different partitions on the disk, or even on different disks altogether, but  logically everything is still in the same location. The best way to grasp this concept is to simply use Linux as your daily driver, as the best way to learn is through immersion. Ubuntu or Linux Mint are probably the best choices for this task. After using the Linux file system for a while, eventually everything will click you’ll understand what’s going on.

Also Read -

Zorin OS 10 A Newbies Frendly Linux Distribution  

PCLinuxOS A Newbies Friendly Linux Distribution

Linux Mint Best Distro for New Linux users