Get to Know Linux: File System Hierarchy - gHacks Tech News

Get to Know Linux: File System Hierarchy

The Linux file system hierarchy is much different than that of Windows. So much so that it becomes a show stopper for many new users. I hope to clear up a lot of the confusion here and now at gHacks. So, without further adieu, I give you the Linux file system hierarchy.

/ - This is the base, or root, of the file system. Everything in the Linux system is housed in this directory.

/bin - This directory contains a number of essential commands that are available to unprivileged users (such as cat, chmod, chown, etc). The /bin directory also houses the shells (such as bash).

/boot - This directory contains everything necessary for the boot process. Without the /boot directory, your machine would not be able to boot up.

/dev - This directory contains all of the special and device files. With Linux all devices and drives have a name. Hard drives tend be labeled as hda, hdb, hdc. Special devices such as external usb devices can be labeled as sda, sdb, sdc.  If you look in the /dev directory you will see quite a few files that can be associated with devices. Most of the devices found here are either block or character devices. Block devices hold data (such as a hard drive) and character devices transmit data (such as a mouse).

/etc - This is a very special directory that contains numerous configuration files and directories. This directory will contain the X configurations, Apache, Samba, the init system, etc. The /etc directory also houses the sources for package management systems like apt and yum. One of the most important subdirectoris in /etc is the /etc/init.d (or in Red Hat based systems, /etc/rc.d/init.d). This subdirectory contains all of the initialization scripts for services such as networking, samba, apache, cron, hal, etc.

/home - This is where all user data is housed. Each user on the system will have their own subdirectory within /home. All user data and user-specific configuration files are saved here.

/lib - This is where all kernel modules needed for system boot libraries that are required by root system commands (commands found in /bin and /sbin.)

/lost+found - If your system crashes or is shut down improperly any lost data will be stored here. During a recovery boot the fsck application will attempt to recover corrupt files found here.

/media - This is where all external media (or extra internal drives) is mounted. If you make or edit entries in the /etc/fstab file you will point devices (such as /dev/sda to directories withing /media.)

/mnt - This is another directory where external (and internal) drives and devices are mounted. This is a holdover to older school thought. Most modern distributions are moving to the /media directory.

/opt - This is a directory that can be used for installing applications that are outside of the default installation. When you install applications here they can be used system wide by all users. Only the root user can install applications here.

/proc - This is a special directory that is actually a virtual filesystem. The /proc directory acts as a process information center for the kernel.

/root - This is the root users home directory.

/sbin - This is where all system maintenance/administration executable files are stored. These commands differ from those in /usr/sbin in that they are system commands used for critical system administration and maintenance whereas /usr/sbin are non-critical tasks such as user administration, network administration, etc.

/usr - This is one of the largest directories on your system as it contains all user-executable binaries as well as the libraries, documentation, and header files for these executables. One of the most important subdirectories is /usr/bin where all user application executables are stored.

/var - This directory contains all variable data such as log files. On a server environment the document root directory of most servers will be found here (/var/www and /var/ftp are examples.)

/srv - This directory can contain the services (such as www) directory in some distributions.

/tmp - This directory, as you would expect, contains temporary files that are stored as needed. Many files you will find here are lock files created by applications. Do not remove anything from this directory as the cron system has a job specifically created for the removal of these files.

And there you have it. A description of each directory in the Linux file system hierarchy.





  • We need your help

    Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

    We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.

    If you like our content, and would like to help, please consider making a contribution:

    Comments

    1. RG said on December 11, 2008 at 9:24 pm
      Reply

      Thank you, this is print worthy. After a while of writing these articles you should compile them and make a Ghacks Linux book :)

    2. my-t-man said on December 11, 2008 at 9:43 pm
      Reply

      First I want to thank you for answering my questions yesterday. Second, I can’t tell you how much I appreciated todays post. I never could seem to find all this in one place before. I will be looking forward to more of your help. Thank you once again.

    3. Paul. said on December 11, 2008 at 9:45 pm
      Reply

      Great i hope you will keep up the good work and go on explaning just as christal clear as you dit up to now.

    4. iampriteshdesai said on December 11, 2008 at 10:38 pm
      Reply

      Uber Sexy :P
      Keep Up The Good Work

    5. gokudomatic said on December 12, 2008 at 12:28 am
      Reply

      really nice. thanks. but as a privileged user, where should I install a software only for me without using root? I suppose /usr, but how should it be structured? That was always one of the biggest questions I was wondering when I was running linux : where are the user apps? where are the conf files? where are the doc?
      And as a developer, like in java, how should I create an installer? I have no idea.

    6. Genisis said on December 12, 2008 at 6:17 am
      Reply

      Copied, Pasted, Saved! Thanks a Million and keep the posts coming!

    7. garbanzo said on December 12, 2008 at 10:07 am
      Reply

      i have not had time to read these linux posts yet, but this weekend i’m going to start compiling them into a PDF. i know absolutely nothing about linux, so i’m very grateful for these posts. thanks jack!

    8. mickay said on December 12, 2008 at 11:53 am
      Reply

      Really great job, Jack. I’m looking forward for more articles of yours.

    9. Dotan Cohen said on December 12, 2008 at 4:46 pm
      Reply

      Do regular end users really need to know this stuff? I think that knowing what /home and /media are is enough. Does the typical Windows user know or care what is in sys32?

    10. fromtheyard said on December 14, 2008 at 9:29 pm
      Reply

      just a reminder…in opensuse, the /home folder is usually situated on a different partition as a security measure.

      .wine folder stores your windows applications if you have installed any.

    11. max said on March 4, 2013 at 11:53 pm
      Reply

      good content

    Leave a Reply