Software & Apps Linux 50 50 people found this article helpful Linux Directory Structure: What It Is And How It Works Different origin stories account for directory differences with Linux & Windows by Aaron Peters Writer Aaron Peters is a writer with Lifewire who has 20+ years experience in technology. His work appears in Linux Journal, MakeUseOf, and others. our editorial process Twitter LinkedIn Aaron Peters Updated on July 22, 2020 Linux Switching from Windows Tweet Share Email One significant difference between Linux and Windows lies in the default system of directory arrangement that you'll encounter after a clean installation of the operating system. Note we're not talking here about the filesystem, which is the technical pattern used to store data on disk. The directory structure we'll review will apply to most Linux distributions regardless of what filesystem they use. What File Systems Are and Common Ones in Use Today Differences Between Windows and Linux Directory Structures To understand at a high level why these operating systems are structured the way they are, it's useful to understand their history. When Windows-based PCs first began their growth curve, in the early days of MS-DOS, Microsoft's operating system specifically focused on microcomputers (what we today more frequently call desktop computers). In those early years, files were stored primarily on floppy drives. They were labeled A: and B: so it was easy to distinguish them. Later, hard disk drives received the C: drive label and additional drive types, such as CD-ROMs or USB-based drives, were assigned subsequent letters. In contrast, Linux descends from Unix, an operating system developed by AT&T in the 1970s. At this time, the "computers" people used were primarily just terminals. They displayed text-based information on screen and provided a keyboard for input. But the heavy lifting was performed by a "system" that could have been made up of multiple physical machines: one for processing, one for storage, and another that provided a specific application. These were all connected over the network, while to users they appeared as a single entity. This client-server configuration that Unix was designed for was exactly the opposite technology from the single-user microcomputer that MS-DOS, and later Windows, supported. A rule of thumb for Linux filesystems is that the root, or top-most level of the filesystem, doesn't contain any stray files. In most systems it might contain the kernel (vmlinuz in the figures), or the heart of the OS, and possibly a ramdisk (initrd) containing data the system needs to get up and running. But aside from these, it should only contain the directories we'll discuss in the below sections (among others). The /bin Directory One of the first directories you'll encounter is /bin. This stands for binaries, and it contains "standard" operating system programs. Here, "standard" refers to basic utilities needed to use the OS in any meaningful way. Examples of programs you'll find here are as follows: cd, or change directory, which operates much like its Windows counterpartFile management commands like cp and mv (copy and move files, respectively).File permissions utilities such as chmod (which changes file permissions) and chown (which changes the owners of those files).The programs that provide your computing environment, such as login (which provides your ability to sign into the machine) and bash or other shells. When you first install a Linux distribution, these programs will be installed as part of the most basic installation, and in many cases can't be removed. The /boot Directory Next up alphabetically is /boot, which contains files the system uses when it starts up. It contains copies of the Linux kernel (the one you see in the root of the filesystem is probably a link to one of these), the initrd, or initial ramdisk for the system, and other related data. The most important thing you should know about this directory is not to mess around in it. The stuff here is handled when your package manager installs and upgrades kernels. If you delete one of the files needed by your current kernel (or the kernel itself), you may end up with an unbootable system. The /cdrom Directory This is something of a legacy directory. It was introduced as a place where the CD could be mounted, or connected, and its contents accessed. At that time it was common to require root, or administrator, rights to mount the CD-ROM. But nowadays it's more common to find CD-ROMs auto-mounted in the /media directory, which we'll discuss a bit later. In the same way, there used to be a /floppy directory. You can see how these came about to make users, who were likely used to Windows, a little more comfortable. But as floppy drives aren't standard components on modern PCs, you may not even see this directory any more. Ubuntu doesn't have it, for example. If your machine does have a floppy drive, you'll likely find it automatically mounted in /media. The /dev Directory One unique aspect of Unix-based operating systems is that everything is a file. Which is to say that files represent everything in the system: running processes, RAM, and yes, storage devices. When you're copying some data to your hard drive, for example, Linux is actually writing data to a file like /dev/nvme0n1p3, which represents the third partition of your SSD. The /dev directory is where all of these special files are kept. If you browse through it, you'll see files for just about every device you can imagine, from the aforementioned NVMe-based solid state drives to hard disks on the SATA (e.g. /dev/sd*) or older IDE (/dev/hd*) connections, as well older ones like the PS/2 mouse port (/dev/psaux). Asterisks represent wildcards; for example, on a SATA-based set-up, your first hard disk will be "/dev/sda," and that disk's first partition will be "/dev/sda1." Its second partition is "/dev/sda2," while the second disk's first partition is "/dev/sdb1." While it's not important for them to be in any particular order, it's important to know which is which. This knowledge will prevent you from overwriting your Windows partition when you meant to install Linux to a new, blank drive you install, for example. The /etc Directory The /etc directory's name, as a place to put any extra, or et cetera files, belies its importance. In practice, this directory houses many of the configuration files that control the entire system. There are two main types of files that reside here: Global configuration files, e.g. the /dev/fstab file used to mount all those hefty drives you have described in the /dev directory above.So-called "skeleton" files, which are used as defaults for user-level settings. An example of this is the /etc/profile file, which contains settings for the Bash shell. When a new account is created, this file copies to the new account as .profile and serves as the starting point until the user customizes it. Many of the sub-directories in /etc are named for the applications they control, so it's easy to browse around here to try to find the file you need to fix an app when it's acting up. The /home and /root Directories Windows aficionados understand the C:\Users directory, which is where the documents and settings for each user of the system reside. Since Unix was from the start a multi-user system, this concept has existed for many years in Linux as the /home directory. Each account enjoys a sub-directory here that contains all the account's data. In fact, a normal, non-administrator user doesn't even have permission to store files elsewhere. The /root directory is the equivalent user folder for the system administrator, or root user. It only differs from /home in its location (to keep potentially sensitive files far away from normal users) and ownership. The /lib Directories As you're probably using a 64-bit operation system, you probably have a couple of directories here: /lib, /lib32, and /lib64. These contain software libraries the kernel uses for its most basic operations. Those that don't contain code specific to the version the processor are in the /lib folder. Those that are version specific are in the /lib32 (32-bit) or /lib64 (64-bit) directories as appropriate. The /media and /mnt Directories Some years back, if you had removable media like a USB thumb drive, before you could use it you'd need to assign it a /dev entry and create a place for in the /mnt (mount) directory. In more modern versions, Linux distributions configure removable media automatically. In fact, depending on the user logged in when the device is connected, the system will create a user-specific directory, mount the device, and make sure that user has the correct permissions to access it. The difference nowadays is that the /media directory is generally used for this purpose. The /opt Directory There was a time not so long ago that you couldn't just hop over to a site and download an Ubuntu package for your favorite application. You'd install many of these programs by running a custom installer, simply unpacking them from their archive, or even building them from their source code. These installation methods weren't unified, and sometimes it was difficult to track where the files had gone and how to uninstall them. The /opt directory was introduced for this optional software, to make sure the rest of your system was unaffected in the event your installation or un-installation went awry. While more developers today are making their apps available in standard package formats (.RPM and .DEB), some of these programs still install to /opt. Whether this directory still makes sense is a subject of some debate in the Linux community, but for now, it remains. And some software still installs there, even from standard .DEB packages. Notably, Google Chrome installs there on Ubuntu-based systems. The /sbin Directory The /sbin directory, like the aforementioned /bin, holds binary utilities. However, this directory is limited to system binaries, and as such only the root user can run its contents. It includes tools like adduser (used to create new user accounts), insmod (used to load hardware drivers to the kernel), and poweroff (shuts the computer down). If you're wondering at that last one, you've got a sharp eye. No, you don't need to be a "super-user" just to turn your Linux system off. On server systems this is the case. But on the desktop, your preferred environment (such as KDE, GNOME, or XFCE) is set up so it can execute that specific command as though it were a root user. The /usr Directory While user data is stored in the /home folders, /usr and its sub-directories hold the majority of installed software for the system. Here installed means whatever is available outside the basic utilities in /bin. For example, it will contain: Applications such as desktop environments, the LibreOffice office suite, the GIMP image editor, and the Firefox web browser.Source code for things like the Linux kernel and hardware drivers.Ancillary files, such as artwork or documentation, for all the above. The /usr directory stores these in its own hierarchy. It contains bin, lib, and sbin sub-directories, which operate just like their higher-up brethren, but contain only things related to software you installed. The /usr/share directory contains assets like icon sets, as well as documentation files. Finally, the original intention of the /usr/local branch was similar to /opt — user-installed, "optional" software. Part of the debate is which of these two should remain. One point in favor of /usr/local is that most software installed from source code is configured to place itself here. The /var Directory The last of the "main" Linux directories, the /var directory contains system data. This means data generated by the system's operations, such as log files (/var/log), caches (/var/cache), and backups (/var/backup). And since Unix (and therefore Linux also) was originally a multi-user system, holding areas for server applications such as email (/var/mail for mailboxes and /var/spool/postfix for outgoing mail) and network printing (/var/spool/cups) instantiate here as well. Other Directories Different distributions use different combinations of standard directories at the root level. Below, we share the directory listing of the root folder for both MX Linux 18.3 Continuum and Ubuntu 19.10 Eoan Ermine. Depending on the distribution, you may encounter other directories, too: /lost+found: There are times when little bits of data get misplaced in the system. If you know you lost something you can check here, although the contents won't be easily identifiable. You'll need to manually inspect their contents to figure out what they are./proc: Everything in Linux can be represented with a file. The /proc directory contains files associated with processes, and you can view them to examine what they're doing (but don't edit these)./run: This is a runtime directory where processes store some temporary data they need, most often as the system is starting up. As with other system-level directories, don't muck about in here./snap: Ubuntu's Snap is a package format that wraps up an application, and everything that app needs, in a container that's isolated from the rest of your system. The /snap directory is where these containers are mounted to the system, in a similar way as storage devices./srv: This directory is where the files served by daemon programs are stored. For example, static web pages served by the Apache web server might be stored in the /srv/www sub-directory./sys: In keeping with the "everything is a file" mantra, /sys and its contents represent settings and information from the Linux kernel, in the same way /proc does for running processes./tmp: If you guessed by the name that this directory holds temporary data, you're correct. System-level programs store info here temporarily. On a Windows-based computer, nothing inherently precludes you from putting directories anywhere you wish, including at the root (C:\) level. On Linux-based systems, however, you should keep data where it belongs. The granular permissions-based system for Linux will generate intentional friction when you force alternative directory layouts from what the system's been designed to accept.