This article is dedicated to explain the typical root directory structure on Linux based systems. This is valuable information for those who want to obtain a deeper understanding of the Linux file-system, and could be used as a cheat-sheet for those who are already familiar with it but need to quickly check the purpose of some system directory. Reading up on my previous article that teaches some basic terminal commands may come in handy, click here to open my previous article in a new tab.
The root directory structure
The Unix based file-system structure is very different from what you are used to work with on Windows. On MS-DOS and later Windows you have drives like the C:\ system drive which contain a certain folder structure with files in them. This has been so for as long MS-DOS and Windows exists and that is what everybody is used to these days. To start off, the Unix based file-system doesn’t know of drives, instead it’s made up of a folder tree. There is a master folder with the name “the root folder”, it’s also know as this character “/”. This is the top level of the folder tree, from here you can traverse down into the file-system. Here’s an image to give you a visual reference to the typical Unix based file hierarchy.
As you can see, the root folder, or “/” has a couple of directories, this are your system directories all the programs on a Gnu/Linux system depend on. I’ll explain the function of each folder a bit by describing the type of files that usually reside in them.
- /bin folder
This folder contains essential system binary files to make the commands such as ls, cp, mv, cd, pwd, and more work. Usually you don’t have to be here and it’s better to stay out of this folder entirely because a slight mistake in this folder can really break your system.
- /sbin folder
This folder contains more essential system binary files to make other essential programs like for example fdisk, mkfs.ext3, parted and fsck.ext3 work. These binaries may also rely on other files that are somewhere in your file-system. Usually it’s a good idea not to move yourself into that folder, you may break programs if you make a mistake. You may go here to quickly see if you’ve got some type of program installed before installing, but don’t go in as root.
- /etc folder
This folder contains essential system configuration files and scripts that allow you to configure programs. The file fstab resides here for example, you can set a file-system table and determine what storage media you want to be mounted during boot up. It’s strongly recommended to do some research before you start to stir around in this folder. A mistake is easily made and you’re system, or other programs may malfunction as a result. Don’t change files in this folder if you’re not exactly sure of what you’re doing.
- /dev folder
Every device inside and outside of your computer is represented by a file on the files-system as a resource. Your hard-drives for example are usually represented by an identifier like /dev/sda or in the case of partitions it also has a number like /dev/sda1 and /dev/sda2. Usually you don’t change working directory to this folder because you’ll damage your system beyond repair if you don’t know what you’re doing. Don’t experiment either, I’m serious. There are a myriad of files in there I won’t go into right now but for now it’l suffice to know that these are file representations of devices in or connected to your computer.
- /proc folder
This folder contains files with process information. Unless you’re manually trying to figure out what some process on your computer is doing you don’t want to be here. There is nothing interesting here and usually programs such as ps or htop provide enough practical information to manage processes. Usually you’re killing processes that are misbehaving, and in some cases you’ll give some process more processor priority. Just don’t change working directory to here.
- /var folder
You’ll usually find various files here, commonly things like program or system logs, log archives, program manuals or example configuration files. This is a good place to look for example configuration files if you can’t find a specific configuration file after installing a program, you’re using Debian so that kind of stuff happens, get used to that as it will make you an excellent problem solver. If you need to find a log of some program that is misbehaving then this is the place to look. You can’t really damage the system by making mistakes in this folder, you’ll only make it harder on yourself because there’s a lot of valuable information in here.
- /tmp folder
This folder usually holds temporary files. Programs or processes may want to write some data to disk in a file in some process that requires data to be put somewhere for later use in such a process. You don’t want to delete files there, it may crash programs if the temp files cannot be found at a certain point in a process. Unless you’re verifying the creation or deletion of a temp file by a program you made yourself you should stay out of it.
- /usr folder
This folder contains user programs, you’ll see that this folder also has a /bin and /sbin folder. It’s good practice to compile programs and copy files and folders to /usr so it’s easy to distinguish between programs you’ve installed using a package manager and programs you’ve compiled yourself. There are also various shared libraries that programs use to reduce installing the same library for different programs. Usually you don’t have to be here unless you’re an advanced user. If you don’t know what you’re doing here you’ll possibly break programs that you’ve compiled or programs that rely on shared libraries.
- /home folder
This folder contains the default username folders whenever an account has been created using the command adduser, in most cases. There are ways to create users without a home folder, this is useful for programs that require a username for file-system purposes. A user folder is completely owned by it’s user and that user has full privileges there. It’s not wise to use this folder for any other purpose. You can harm your system pretty destructively if you delete a folder within /home because a lot of programs store user related information in someones home folder.
- /boot folder
A very important folder or partition. This folder contains crucial information to boot up your system. Usually the kernel and initramfs reside here. You don’t want to mess around with this unless you exactly know what you’re doing. You’ll damage your system quite effectively if you manage to accidentally delete something here. Staying away from it is usually good practice.
- /lib folder
This folder contains various important system libraries. Kernel libraries and driver libraries are part of that so be careful in there. There are certain situations that require some modifications in this folder, for example if you’ve got a system that’s supporting multiple architectures (i386 and AMD64) and need to symbolically link some 32 bit libraries to their 64 bit counterpart. Otherwise just stay away from this system folder.
- /opt folder
This folder holds optional files and folders for optional apps and services. I’ve not used this folder in any problem solving occasion neither have I had to mess around in it so leave it for what it is. I bet it’s also empty on your Debian 8 setup.
- /mnt folder
This is usually a good place to mount various storage media, if you have a lot of storage media that need to be mounted. Linux doesn’t care where in the file-system you mount a storage media but this folder is there just to make mounting storage media a whole lot more easy. It’s good practice to mount hard drives or network drives here. Just create a folder and mount a storage media on it.
- /media folder
The Debian system usually mounts USB thumb drives or external hard-drives in here when it’s plugged in and detected. You can also mount stuff here instead of /mnt. You should be careful to unmount usb drives before unplugging but other than that you’re safe from mistakes in this folder.
- /srv folder
It’s used to store service data, however I bet it’s empty on your system. I also have no further idea as to why this folder exist. The fact that it’s empty on my system and probably any other regular system tells me that this folder isn’t really that important for now. just leave it and don’t use it, it’s only consuming an insignificant 4Kbyte of space so don’t even bother deleting it.
You should now have a very basic understanding of the root directory structure of a Linux distribution. Your homework assignment is to navigate a little bit through this direcotry-structure to familiarize yourself with the files that are inside. Don’t do anything with the files as you may damage your system if you don’t know what you’re doing. Click here if you want to learn how to navigate through the directory structure by learning some basic commands.
Good luck and have fun. As always thank you for reading my articles.