SEARCH

How-To Geek

HTG Explains: The Linux Directory Structure Explained

image

If you’re coming from Windows, the Linux file system structure can seem particularly alien. The C:\ drive and drive letters are gone, replaced by a / and cryptic-sounding directories, most of which have three letter names.

The Filesystem Hierarchy Standard (FHS) defines the structure of file systems on Linux and other UNIX-like operating systems. However, Linux file systems also contain some directories that aren’t yet defined by the standard.

/ – The Root Directory

Everything on your Linux system is located under the / directory, known as the root directory. You can think of the / directory as being similar to the C:\ directory on Windows – but this isn’t strictly true, as Linux doesn’t have drive letters. While another partition would be located at D:\ on Windows, this other partition would appear in another folder under / on Linux.

image

/bin – Essential User Binaries

The /bin directory contains the essential user binaries (programs) that must be present when the system is mounted in single-user mode. Applications such as Firefox are stored in /usr/bin, while important system programs and utilities such as the bash shell are located in /bin. The /usr directory may be stored on another partition – placing these files in the /bin directory ensures the system will have these important utilities even if no other file systems are mounted. The /sbin directory is similar – it contains essential system administration binaries.

image

/boot – Static Boot Files

The /boot directory contains the files needed to boot the system – for example, the GRUB boot loader’s files and your Linux kernels are stored here. The boot loader’s configuration files aren’t located here, though – they’re in /etc with the other configuration files.

/cdrom – Historical Mount Point for CD-ROMs

The /cdrom directory isn’t part of the FHS standard, but you’ll still find it on Ubuntu and other operating systems. It’s a temporary location for CD-ROMs inserted in the system. However, the standard location for temporary media is inside the /media directory.

/dev – Device Files

Linux exposes devices as files, and the /dev directory contains a number of special files that represent devices. These are not actual files as we know them, but they appear as files – for example, /dev/sda represents the first SATA drive in the system. If you wanted to partition it, you could start a partition editor and tell it to edit /dev/sda.

This directory also contains pseudo-devices, which are virtual devices that don’t actually correspond to hardware. For example, /dev/random produces random numbers. /dev/null is a special device that produces no output and automatically discards all input – when you pipe the output of a command to /dev/null, you discard it.

image

/etc – Configuration Files

The /etc directory contains configuration files, which can generally be edited by hand in a text editor. Note that the /etc/ directory contains system-wide configuration files – user-specific configuration files are located in each user’s home directory.

/home – Home Folders

The /home directory contains a home folder for each user. For example, if your user name is bob, you have a home folder located at /home/bob. This home folder contains the user’s data files and user-specific configuration files. Each user only has write access to their own home folder and must obtain elevated permissions (become the root user) to modify other files on the system.

image

/lib – Essential Shared Libraries

The /lib directory contains libraries needed by the essential binaries in the /bin and /sbin folder. Libraries needed by the binaries in the /usr/bin folder are located in /usr/lib.

/lost+found – Recovered Files

Each Linux file system has a lost+found directory. If the file system crashes, a file system check will be performed at next boot. Any corrupted files found will be placed in the lost+found directory, so you can attempt to recover as much data as possible.

/media – Removable Media

The /media directory contains subdirectories where removable media devices inserted into the computer are mounted. For example, when you insert a CD into your Linux system, a directory will automatically be created inside the /media directory. You can access the contents of the CD inside this directory.

/mnt – Temporary Mount Points

Historically speaking, the /mnt directory is where system administrators mounted temporary file systems while using them. For example, if you’re mounting a Windows partition to perform some file recovery operations, you might mount it at /mnt/windows. However, you can mount other file systems anywhere on the system.

/opt – Optional Packages

The /opt directory contains subdirectories for optional software packages. It’s commonly used by proprietary software that doesn’t obey the standard file system hierarchy – for example, a proprietary program might dump its files in /opt/application when you install it.

/proc – Kernel & Process Files

The /proc directory similar to the /dev directory because it doesn’t contain standard files. It contains special files that represent system and process information.

image

/root – Root Home Directory

The /root directory is the home directory of the root user. Instead of being located at /home/root, it’s located at /root. This is distinct from /, which is the system root directory.

/run – Application State Files

The /run directory is fairly new, and gives applications a standard place to store transient files they require like sockets and process IDs. These files can’t be stored in /tmp because files in /tmp may be deleted.

/sbin – System Administration Binaries

The /sbin directory is similar to the /bin directory. It contains essential binaries that are generally intended to be run by the root user for system administration.

image

/selinux – SELinux Virtual File System

If your Linux distribution uses SELinux for security (Fedora and Red Hat, for example), the /selinux directory contains special files used by SELinux. It’s similar to /proc. Ubuntu doesn’t use SELinux, so the presence of this folder on Ubuntu appears to be a bug.

/srv – Service Data

The /srv directory contains “data for services provided by the system.” If you were using the Apache HTTP server to serve a website, you’d likely store your website’s files in a directory inside the /srv directory.

/tmp – Temporary Files

Applications store temporary files in the /tmp directory. These files are generally deleted whenever your system is restarted and may be deleted at any time by utilities such as tmpwatch.

/usr – User Binaries & Read-Only Data

The /usr directory contains applications and files used by users, as opposed to applications and files used by the system. For example, non-essential applications are located inside the /usr/bin directory instead of the /bin directory and non-essential system administration binaries are located in the /usr/sbin directory instead of the /sbin directory. Libraries for each are located inside the /usr/lib directory. The /usr directory also contains other directories – for example, architecture-independent files like graphics are located in /usr/share.

The /usr/local directory is where locally compiled applications install to by default – this prevents them from mucking up the rest of the system.

image

/var – Variable Data Files

The /var directory is the writable counterpart to the /usr directory, which must be read-only in normal operation. Log files and everything else that would normally be written to /usr during normal operation are written to the /var directory. For example, you’ll find log files in /var/log.


For more detailed technical information about the Linux file system hierarchy, consult the Filesystem Hierarchy Standard documentation.

Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

  • Published 06/25/12

Comments (36)

  1. Cal

    Excellent post. I wish I had this 6 years ago. Keep up the good work HTG.

  2. Jeff

    Finally, an article about Linux folders that makes sense to an old Windows guy like me. Well done, Chris!

  3. TheFu

    Excellent article.

    Once folks understand Linux/UNIX a little, they can understand that almost every file placement has a purpose.

    These directory structures often apply to individual programs subdirectories too. Support we are creating a new “SuperProgram”, then we’d probably have this directory structure as part of our distribution of “SuperProgram”:

    SuperProgram
    |____bin
    |____lib
    |____etc
    |____man
    |____doc
    |____share

    There might be a contrib/ subdirectory for addons by 3rd parties too. In general, files are put into the correct subdirectory so we don’t need to hunt for them. Settings into etc/, programs and scripts into bin/.

    Simple. Easily understood and relatively self-contained. Picking up the entire SuperProgram/ directory structure and moving it somewhere else probably gets all the files necessary to make it work.

    In the old days when disk storage was tight, /usr was shared across many servers using NFS – Network File System – with a read-only mount. That meant is wasn’t possible to install files there locally, so /usr/local was created for locally installed programs. You still needed “root” to install stuff there, which was fairly uncommon in a business environment, so lots of us would install programs under $HOME/local/ .

    Often our $HOME directories was also NFS mounted and shared between many different UNIX OS installations – not binary compatible. This meant $HOME/local would need some method to differentiate between different binary platforms. Today, that might be x86, amd64, arm, mips, sparc, powerpc and others.

    Platform independent programs and script programs just got put into ~/bin/ …. which is what many people still do. Every script I create that isn’t too trivial gets put into $HOME/bin/ for use later or just as a reference.

    In general, Linux follows the UNIX directory structure, but they’ve migrated away under some situations due to platform requirements or slightly different use cases. Even when I personally disagree with the changes, I know they’ve carefully considered alternatives and at least the new structure won’t be dumb.

    Suggest that the next article for Deeper Linux Understanding – “Everything is a file.”

  4. acorn

    I Have great respect for most of HTG presentation
    except where I fill out a “free” download of data only to disvover it is a fishing hook. ie a company wants all my working data. That must be what ‘sponsored’ means. I am retired now and cannot honestly fill in the data. I will not lie. Hence the free download is a misrepresentation. Last eg is the windows 7 article on this issue.

  5. GuitarZaan

    acorn, I couldn’t agree with you more as I’m in the same boat as you.

    HTG Very informative article in the directory hierarchy and the file types stored within. Thanks much.

  6. Carlos C

    As always. An easy, understandable read. I always enjoy ur articles.

  7. Doug

    I agree 100% with acorn and GuitarZaan regarding my ability to honestly download the offering of the day, since I am retired and have no employer. I am always happy to see that useful sites like HTG have sponsors to help with the bills, and wouldn’t hesitate making a donation or buying a subscription if option were available.

    I would like to see HTG request or suggest that the sponsor provide a means for those of us with no data to give to download whatever they are offering. They could be doing themselves a favor by not having to sift through as much phoney data that confuses the effectiveness of their sponsorship.

    And thanks for a good article on Linux. It’s been in the back of my mind for some time as something I should get familiar with. I’ll look for more in the archives and for new articles.

  8. Citrus Rain

    This is a good reference.

    I figured out media and home a long time ago, but I am still trying to memorize (through repeat set-up of Filezilla to use Bluefish as the default editor) where the programs are.

  9. sureh

    simply nice

  10. Neel

    Nice post! very informative! thx for the share

  11. electroyeti

    Great Job this will help convert all those folks from windows/dos thinkers to Linux thinkers

  12. Dave

    Yup, I do not mess with the “free” down loads. Been screwed by a couple that asked for personal information I do not think they need

    first one I never got a down load even tho I filled in the information requested

    My opinion, they are mis representations by How To Geek

    Not what I expect

  13. LOST

    Simply informative !! THANKS :D

  14. ntroling

    Well done!

    Looks like this has been a great help to many…

  15. Dan Saint-Andre

    Those with more interest might visit the pages found here:
    https://www.linux.com/learn/tutorials/476610-a-look-at-the-filesystem-hierarchy-standard-30

    There is a revision to the plans for how the linux file-system hierarchy works in the works.
    This link discussion some of those plans.

    ~~~ 0;-Dan

  16. mohamed

    I am not sure but I think that Apache puts the website root in /var/www

  17. TheFu

    @Mohamed – the use of /var/www wasn’t always that way. Used to be that almost all self-installed programs did the bin, lib, var, etc in subdirectories under the program name (see my other comment), but that caused issues on shared file systems (like when a single apache binary is shared across 20 servers), so distro makers came up with a few places to default apache htdocs
    * /srv/
    * /www/
    * /opt/
    * /var/www/
    were tried if my memory is correct. /var used to be purely for system files, mainly log files, and was a relatively small partition.

    Not all distros default to /var/www for web files, but it is a very popular choice. These defaults can be changed easily in the apache configuration files … which are under /etc/ now, but used to be stored closer to the program itself in a etc/ subdirectory.

  18. Dan

    I too wish I’d seen this a few years ago when starting out with Linux.
    I must say the file structure in Linux has always been one of the big turn offs for me. It’s so complicated and cryptic in its folder names, I always longed for the simple Windows structure of ,Program Files, Documents, Windows and so on.. It makes finding things a whole lot easier.

  19. M Henri Day

    Excellent blog post, Chris ! I dare say this will prove useful in explaining a Linux distro like Ubuntu to my retirees who just possible be put off by the coming Windows 8 and Metro and start looking for an alternative….

    Henri

  20. Anonymous

    @Dan

    I know what you mean. It’s as if the Linux crowd never heard of SUB-directories. Either that or they try desperately to avoid them. Linux sub-directories are there but when you compare to Windows it’s like every possible sub-directory was moved out so it’s all a flat tree – where file paths from the root are kept as short as possible. I realize this isn’t exactly true and that there are some pretty deep sub directories in nearly every Linux distro, but from a top level first glance it doesn’t seem like it and that just adds to the confusion, if you ask me.

    For example, in Windows you have the C:\Windows\System32\drivers sub-directory whereas a similar example in Linux (Ubuntu) might simply be the /dev directory. Bad translation I’m sure, but you get the idea. Why not take system stuff like /dev and put it in a /Ubuntu/dev directory? Then move all the other stuff like that (/Ubuntu/etc, Ubuntu/proc and so on) so that all you see in the root are a few directories that make sense? I’m sure there are reasons for Linux’s relatively flat paths like this, possibly so various directories can be placed on other partitions, but it’s still confusing to old Microsoft-OS users like myself. (You too?)

    It would make more sense to me if user data and system stuff were better segregated from a top level view. I understand why the /Media and /Home directories are there as well as why the /boot directory is often hidden. But why not shove everything else in a top level directory? Something like /Ubuntu or /SuSE or /??? Stuff an average “dumb user” isn’t likely to mess with. (Maybe other OS’s like BSD do this but I’ve not seen it.)

  21. grizzle

    Get over your free download and having to fill out a form old man. How do you think htg get funded? Do you think this is the only place on the internet you will be asked to give information? Do you think someone knocking on your door or stopping you in the street wanting to give you something wants nothing in return? It’s called business. Nice article. I think I’ll give ubuntu another go

  22. tech27

    Why is that when I open the ‘/lost+found’ folder (using Zorin OS core 6) it say’s I don’t have permission on opening it, even though I’m the administrator. Any answers?

  23. Josh B.

    This post is excellent. May it continue to drive traffic to the HTG.

  24. Keksys

    I believe /media and /mnt will wanish on next iteration of Ubuntu. Now partitions are mounted in /run directory, try Ubuntu quantal daily or Alpha 2 (tomorrow).

  25. crond

    Good one.
    But, I doubt about some parts and feel this is little bit biased with Ubuntu.
    /bin – is a totally unclear.
    /media – regarding the automatic mounting, the actual Linux wont do that, unless the user made the entries in /fat-c . For the very user friendly distros like Ubuntu, Mint this is OK.

  26. Lo

    Why not create a ~/.etc directory instead of putting every user config files at the root of ~/

  27. cam2644

    Great article – well laid out and lucidly informative!

  28. musicengineer

    Wish I had seen this in 1992 when I couldn’t spell Unix. In 20 years I have learned that whatever I see being done in Unix has a reason. Often the reason is security, and Microsoft never learned to spell that one. I still can’t fathom why grub2. Grub2 is in line with Unix thinking, but a complicated solution to a non problem, like every new Windows OS version.

  29. Keith Taylor

    Thank you, thank you, thank you HTG! I have been using Zorin for a few months now and am very impressed with Ubuntu. This explanation helps me to understand more about my OS, which is always a good thing. All newbies should be directed Zorin: my wife, who was once OK with wUndos until a batch of viruses destroyed all her info, is now adamant that she will never go back after teething on Zorin.

  30. Dave

    /usr is NOT ‘user’ it is USR for Unix System Resources.
    Just thought this should be put out there.

  31. Anders

    Great article, but they forgot the /usr/local directory.

    About complicated, Dan and Anonumous. Windows is a mess.

    They are there because there are different purposes. They are not just put in a large directory with all program.
    Can you tell me where all the program in the Start > Program menu comes from? I know, but it wasn’t easy to find out.

    You can think of / as system directory with important stuff that is needed when the computer boots.
    /usr is for when the computer is up and running. So there you have your programs installed by the distribution.
    In /usr/local you have all programs that you and your administrator install programs for all users to se and use.
    In /home/$USER/ you put your private stuff, like programs you install yourself.

    All these “points” then have mostly the same subdirectorise, there are some few exceptions like /dev and /proc and /boot. But when you see them, you know what to expect from them. like bin/ contains programs in each of the “points” (/bin /usr/bin /usr/local/bin).

    bin/ is for user binaries, that is programs (.EXE and .COM for you old MS Windows guys)
    sbin/ for administrations binaries, which isn’t usually run
    lib/ for program libraries, which is almost like DLL in MS Windows, but cleaner. No data, only code.
    share/ is stuff that could be share over the net between different computers (like ARM and x86).
    etc/ are for configurations files (but they are usually move to /etc for /usr).

    There are some other, but you get the point. It isn’t that many places where you find programs, and you find them on each place because the should not interfere with each other (heard about DLL-hell in MS Windows?).

    And Dan, /dev is for DEVICES, not software like driver routines. They are in another place. You can write text to /dev/tty and it will come up on your screemn, because it IS the screen device. Same with /dev/ttySa which is the first serial port. And /dev/ttyUSB0 is the fitst serial USB device. There are nothing like /dev in MS Windows. They do not have that concept, at all.

  32. Chavoux

    @Anonymous: The Linux directory structure is basically the same as the UNIX directory structure, a standard from long before DOS even existed. And you are right that the ability to mount different parts of the file system on different partitions/disks (and with different permissions) was an important reason for the directory structure. Also the fact that is was from the beginning designed to be a multi-user and multi-tasking OS (in contrast to DOS) played a big role. These options are still important when using Linux as a server with multiple users and a single (or few) system administrators. The fact that only the /home/$USER directory is writeable by a normal user (and that the different directories have different permissions) is an important security feature preventing both malware from subverting the whole system or a user from inadvertently damaging the whole system.

    Actually what you are asking for is already there… the average “dumb user” is not really supposed (or should not need to) mess with anything outside his/her own /home/$USER directory. It is almost better than the “My Documents” folder of Windows, because it can have both documents and (private) programs. The only time you need to bother about the “system files” (everything else under the root directory), is when you need to install or configure new programs (in which case you will need to use su or sudo to works as an administrator/root). Even then your package manager (apt / rpm / Synaptic) will do most of the work for you. It is only of you want to tweak things or experiment (and learn more) that you really need to bother about the Linux directory structure.

    On Windows a lot is hidden away that is easily seen on a Linux system (and can be tweaked by the administrator)… e.g. most of what is put in the “Registry” in Windows is stored in the /etc files in plain text format (but not writeable by a normal user). You ask: “Why not take system stuff like /dev and put it in a /Ubuntu/dev directory? Then move all the other stuff like that (/Ubuntu/etc, Ubuntu/proc and so on) so that all you see in the root are a few directories that make sense?” One reason is that the root really _is_ the system stuff (i.e. you are not supposed to play around in the root directory unless you are an administrator). The second reason is that after you get used to the UNIX way of doing things it actually starts to make perfect sense and it is the Windows way of doing things that starts to become confusing (E.g. you have autoexec.bat and a whole lot of .SYS files right in you root directory! Both C:\Windows and C:\Windows\System32 has both executables and library files all mixed together!).

  33. Jer

    I’ve recently began playing around with Linux and checking out the various distro’s and apps etc. I found the file-system pretty intuitive despite that I’ve been using DOS/Windows since the x286 days. Intuitive in an abstract sense in that I was able to navigate and accomplish everything I was trying to do, without a clear understanding of what a lot of things really were or how it actually worked.

    So this article was very interesting to me and put much in perspective. Thanks!..

  34. Nathan J.

    Thanks for the insight. I actually want to get into Linux since Windows 7 crashed and burned pretty hard on me the other day. I actually installed Ubuntu 12.04 LTS straight away, but it didn’t like my video card, and put the left half of my screen on the right. Challenge accepted, I said, I’ll just log in and update the drivers, problem solved, right? Wrong, it wouldn’t even let me log in. I installed Windows 8 Release Preview, and it was running like a dog, but I ran the disk check utility and it found drive errors. It’s been great since. I want to give Windows 8 a chance, but I really want to dive into Linux. I’m just real sick of Microsoft. This article and some of the comments were real helpful.

  35. knipknup

    @Anonymous use ~/home and don’t mess with anything else.

    @TheFu reading your comments makes me wish I got into unix/linux 20 years ago instead of recently. I’m making up for lost time and this article and your comments really help.

    Thanks!

  36. Aleve Sicofante

    Articles like these are only necessary because the Linux directory structure is a mess full of inconsistencies. Moreover, different authors will sustain different explanations of it, go figure… I know it’s been inherited from Unix and that some really really old historical reasons are behind some of it, but that’s no excuse for keeping things broken.

    GoboLinux is an interesting attempt to bring some logic and reason into this disaster. I wish Linus himself gave it a thought. I won’t hold my breath though. :(

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!