Most people who have used Linux have seen the root directory, but not everybody understands what the directories are used for. A Windows user opening the file manager looks very much like opening the home folder in Windows, and all looks very familiar. You’ve got your documents, your downloads, your pictures, your videosโsame thing. That is until they explore up the tree, looking for the C drive. Where’s Program Files? Where’s the directory that Linux is installed in? How do you find anything? Let me explain.
I’ll take a quick minute here for new Linux users coming from Windows. Windows and Linux evolved in very different ways. Once upon a time, there was a thing called MS-DOS, the Disk Operating System. It was command-line only, but you could still run programs, games, and WordPerfect, but you didn’t need Windows. Windows was added to PCs, and you could install it on top of DOS. You would start up your computer and type in “win” to start Windows. It used letters to assign drives, with A and B being removable disks since early PCs only had floppy drives. With the addition of hard drives, the letter C became the letter for your internal disk. Additional disks were given the next available letter. You could install things in DOS wherever you wanted to. Windows installed itself in its own directory called, funny enough, “Windows.” Later, Microsoft changed how it booted by evolving their kernel to be less and less dependent on DOS and eventually allowed Windows to boot directly without DOS at all. Microsoft’s file directory structure kind of stayed the same.
Understanding Linux File Structure
Now, Linux is different, and so is its file structure. It also doesn’t install applications like Windows does. Starting with Windows 95, Microsoft created the Program Files directory, which was the default installation directory for most applications.
For the most part, Linux follows UNIX traditions, which is why it uses the forward slash instead of the backslash like Windows. Linux also cares about capitalization, so you can have things like “file,” “File,” “FILE,” “fiLe,” and so on. As you can see, while they’re all named “file,” they all use different capitalization, so Linux will allow this because they’re technically not named exactly the same.
Key Features of Linux File Structure
UNIX Tradition
Mac users who have explored their hard drives might find Linux a little more familiar. This is because Macs also evolved from a UNIX ancestor, more specifically BSD. So let’s have a look at the root and go over how all this works. This layout, for the most part, is outlined in the Filesystem Hierarchy Standard, or FHS, which defines the structure and layout and is maintained by the Linux Foundation.
Flexibility in Structure
I want to note here that not all distributions follow this; some do their own special thing. Also, several ways of structuring the folders have changed over the years, but most of what follows still applies in most cases.
Overview of Main Directories
Letโs explore the main directories youโll find in the Linux file structure:
/bin (Binaries)
So let’s go end-to-end, starting with bin
, “bin” being short for binaries. These are the most basic binaries, which is another word for programs or applications. Things like ls
to list your directory, cat
to display the output of a file, and other basic functions are stored here.
- What it contains: Basic binaries or applications like
ls
to list directories,cat
to display file content. - Purpose: These programs are necessary for basic functions.
/sbin (System Binaries)
These are system binaries that a system administrator would use and that a standard user wouldn’t have access to without permission. Both of these folders contain the files that need to be accessible when running in single-user mode, as opposed to the usual multi-user mode. Single-user mode is a special mode that boots you in as a root user to allow you to do system repairs and upgrades or testing. Networking is usually disabled in this mode because of security issues. When you install a program in Linux, it’s typically not placed in these folders.
- What it contains: System binaries that only administrators can access.
- Purpose: Used for system administration tasks and are accessible when running in single-user mode.
/boot
Next is boot
. This is a folder you don’t want to play around in. It contains everything your OS needs to boot. In other words, your bootloaders live here.
- What it contains: Essential files for the OS to boot, such as bootloaders.
- Warning: Do not alter this directory unless you know what you’re doing.
/cdrom
Next, we have “cdrom,” which I’m going to skip because it’s not in all distros and it’s more of a legacy mounting point for your CD-ROM.
/dev (Devices)
So let’s move on to dev
. This is where your devices live. Linux, again following UNIX, has a standard where it was decided everything is a file. Here you’ll find your hardware. A disk, for example, would be dev/sda
here, and a partition on that disk would be, for example, dev/sda1
, dev/sda2
, and so on. You can also find everything else here, from your webcam to your keyboard. This is typically an area that applications and drivers will access and is rarely something a user should be dabbling in.
- What it contains: Files representing hardware devices like disks (
/dev/sda
for disks,/dev/sda1
for partitions). - Purpose: Provides access to hardware resources.
/etc (Configuration)
So going back to root, the next folder is etc
. The name of this folder has been argued as standing for “et cetera,” but it is generally used for configuration files. Here, system-wide configurations are stored. For example, in this folder, you would find the list of all your sources, what repositories your system connects to, as well as its various settings. So if you’re looking for something that is a system-wide application and not a per-user setting, for example, LibreOffice would have settings in each user’s folder, and it wouldn’t be system-wide because each user can have different settings.
- What it contains: System-wide configuration files. For example, APT repositories and sources.
- Purpose: Store system-wide settings for various applications.
/home
And this brings me to the next folder, which is home
. However, I’m going to save this for the end because there are some things I want to discuss about it, so we’ll come back to it later.
- What it contains: User directories where personal files and settings are stored.
- Note: Weโll come back to discuss this folder later.
/lib, /lib32, /lib64 (Libraries)
Next are the lib
folders. This includes lib
, lib32
, and lib64
. These are where the libraries are stored. Libraries are files that applications can use to perform various functions. They’re required by the binaries in bin
and sbin
, for example.
- What it contains: Libraries required by the binaries in
/bin
and/sbin
. - Purpose: These provide essential functions that binaries rely on.
/media, /mnt (Mount Points)
Moving on, we have media
and mnt
, or mount
. These directories are where you would find your other mounted drives. It could be a floppy disk, USB stick, external hard drive, network drive, or even a second hard drive. So if you’re looking for that A, B, or D drive, this is where you want to be looking. Now, this media
folder wasn’t always around. It was typically just mnt
, and that’s where you mounted your storage devices. Nowadays, most distros automatically mount devices for you in the media
directory, so your USB stick that you inserted would be in media/username/devicename
. So why are there two directories? Well, if you’re mounting things manually, use the mnt
directory and leave the media
directory to the OS to manage.
- What it contains: Mount points for additional drives like USB sticks, external hard drives.
- Purpose:
/media
is for automatic mounting, while/mnt
is for manual mounting.
/opt (Optional)
Next down the line is opt
. This is the optional folder, which is usually where manually installed software from vendors resides, though some software packages found in the repo can also find their way here. VirtualBox guest additions are one example. This is also where you can install software you’ve created yourself. This folder is where I place all the applications I’ve written first on Linux.
- What it contains: Manually installed software from vendors, such as VPN software.
- Purpose: Reserved for optional, third-party software.
/proc (Processes)
Next, we have proc
. “Proc” is where you’ll find pseudo files that contain information about system processes and resources. For example, every process will have a directory here, which contains all kinds of information on that process. So, for example, here I can open the status file, and it’ll show me all kinds of information on that process. There’s tons more in here, but this isn’t something you want to play in. If you are a developer, if you’re writing applications, this is very handy. Here you can also find information like, for the CPU, this will give you all kinds of information on the CPU, and you can also do uptime, which will print out your system’s uptime.
- What it contains: Information about system processes and resources, such as CPU stats.
- Purpose: Pseudo-files representing process-related data.
/root
Next is root
. “Root” is the root user’s home folder. Unlike a user’s home folder, it does not contain the typical directories inside, and it does not reside in the home directory. You can store files here if you wish, but you need root permissions to access it. The location of this directory also ensures that root always has access to its home folder, in case you have the regular user’s home directory stored on another drive, which you cannot access.
- What it contains: Home directory for the root user.
- Purpose: Ensures the root user has access to its home directory, even if user directories are on another drive.
/run
Next is run
. This one’s fairly new, and different distros use it in slightly different ways. It’s a “tmpfs” file system, which means it runs in RAM. This also means that everything in it is gone when the system is rebooted or shut down. It’s used for processes that start early in the boot procedure to store runtime information that they use to function.
- What it contains: Runtime data stored temporarily in RAM.
- Purpose: Stores information required by processes that start early during boot.
/snap
We’ve already covered sbin
, so next down the line is snap
. This is a folder where Snap packages are stored and are mainly used by Ubuntu. Snap packages are completely self-contained applications that run differently than regular packages and applications. This will be covered in a future article on its own since it’ll take more time to explain.
- What it contains: snap packages are self-contained here.
- Purpose: To allow applications to run independently of the underlying system, snaps create an isolated environment for the contained applications1.
/srv (Service Data)
srv
is the service directory where service data is stored. It’ll probably be empty for you, but if you run a server such as a web server or FTP server, you would store the files that will be accessed by external users here. This allows for better security since it’s at the root of the drive, and it also allows you to easily mount this folder from another hard drive.
- What it contains: Data for services like web servers or FTP servers.
- Purpose: Provides secure storage for external access files.
/sys (System Information)
Next down the line is sys
. The system folder has been around a long time. It’s a way to interact with the kernel. One older example is writing to a file using “VGA switcheroo” to change settings on graphic cards in a hybrid system. This directory is similar to the run
directory, and it’s not physically written to the disk. It’s created every time the system boots up, so you wouldn’t store anything here, and nothing gets installed here.
- What it contains: A way to interact with the kernel and system settings.
- Purpose: System configurations, not physically written to disk.
/tmp (Temporary Files)
tmp
is, of course, a temp or temporary directory. This is where files are temporarily stored by applications that could be used during a session. One example is if you’re writing a document in a word processor, it will regularly save a temporary copy of what you’re writing here so that if the application crashes, it can look here to see if there’s a recently saved copy that you can recover. This folder is usually emptied when you reboot the system. On occasion, you might find some files or directories that remain and could be stuck there because the system can’t delete them. This normally isn’t a big deal unless there are hundreds of files or the files are taking up a lot of disk space, in which case you might want to log in as the root user in single-user mode, navigate to this folder, and manually delete them.
- What it contains: Temporarily stores files like cache or word processing autosaves.
- Note: Emptied on reboot, but sometimes old files might linger.
/usr (User Applications)
Moving on, we have the usr
folder. This is the user application space where applications will be installed that are used by the user, as opposed to the bin
directory, which is used by the system and system administrators to perform maintenance. It’s also known as the UNIX System Resource, and any applications installed here are considered non-essential for basic system operation. Installed applications will reside in one of several places here, such as usr/bin
, usr/sbin
, or local/bin
, with their required libraries stored in usr/local/lib
or usr/lib
. Most programs that are installed from source code will end up in the local folders. Many larger programs will install themselves into usr/share
. Any installed source code, such as the kernel source and header files, will go into the src
directory. This directory seems like a confusing mess at first, and while the directory structure and what goes where is laid out in the FHS I mentioned earlier, you’ll still have to sometimes look in other places to find things. Someone making a certain application might not adhere to the standard and could just do what they want. Also, some distros may treat these folders differently as well.
- What it contains: Non-essential applications used by the user.
- Purpose: Houses user-installed applications in directories like
/usr/bin
,/usr/sbin
.
/var (Variable Data)
Going back to root, we have var
. Var is the variable directory. It contains files and directories that are expected to grow in size. For example, var/crash
holds information about processes that have crashed. var/log
contains log files for both the system and many different applications, which will constantly grow in size as you use the system. You’ll also find other things here, like databases for mail and temporary storage for printer queues, also known as the spool
.
- What it contains: Files that grow over time, like logs, crash reports, and printer queues.
- Purpose: Stores data that changes as the system operates.
The Home Directory Explained
When you enter the home folder, you’ll see that each user has their own folder inside of it. The home folder is where you store your personal files and documents. Like I said, each user has their own home folder, and each user can only access their own unless they use admin permissions. Some users mount the home folder on a different drive or partition, which allows you to reinstall your system and preserve your files. The home folder also contains many different directories which store your application settings.
Hidden Directories
A hidden directory is simply one that starts with a period. Linux hides these by default. You can view them in the file manager by selecting “Show Hidden Files” or by pressing Ctrl+H. This is, of course, using Nautilus in GNOME, and some file managers might be different. PCManFM also uses Ctrl+H to view hidden files. If you’re in the terminal and you list files, it’ll only show you what is not hidden unless you specify “-a” for all, and now you can see all your hidden files.
Customizing and Backing Up
These hidden directories store things like cache, some applications like a browser use to store temporary files, and other applications might store thumbnails or information that will be used repeatedly.
Then you have folders like config
and local
, which store individual application settings. Geany, for example, can be found in config
, so here’s the Geany folder. Any settings that I change in the Geany options are saved here.
If you go back to the home folder, you can see that some applications store their settings straight into the home folder, like GIMP, for example. These hidden folders are also where your desktop settings are saved. Whether you use Openbox, KDE, GNOME, or Unity, they all save their settings here, such as what wallpaper you use, what theme you use, and so on.
You can even place your icons and themes in these folders so that you can have a custom look and easily save them for reuse. These hidden folders are important if you want to back up your files and your settings. If you don’t customize your system or you don’t care to, then you can simply back up all the folders you see here. If you want to save all your settings, then you might want to include all the hidden files as well, so if you reinstall your system, you simply log in, and all your theming will already be done just like you left it. You will have to reinstall your applications, but once you install them, the settings you set for them will already be in place, and the applications will run just like they did before.
Conclusion
As you can see, Linux is kind of similar to Mac but very different from Windows. Although it seems like a mess, it’s actually a more efficient way of doing things and allows much more sharing of common resources between packages.
When it comes to adding and removing software, your distro will have a package manager that will handle all this for you. The package manager tracks where everything is going so that when you remove your package, it takes all those files with it.
I hope you found this informative. I did put quite a bit of work into preparing it, and I’ll have quite a bit of editing to do now. Most importantly, if you found it useful, please share it by clicking that share button and spread it out to your Twitter, Facebook, or whatever platform you use.
Foot Notes:
No Comment! Be the first one.