Understanding the Linux Directory Layout

The layout

A quick ‘ls’ command will show you the directory structure of any linux system. Just go to the root directory, ‘cd /’ and type ‘ls’. In my current system, Ubuntu 8.10 I have:

root-directory

bin

Bin contains the system binary files that are essential for general operation of your computer. These exectuable files are the next line after the system kernel. Withtout these you can’t do a whole lot of anything on your computer. Some of these include:

dev

If you are used to other operating systems this will be weird for you. As everything in Linux devices are represented as a directory. This makes it easier for other programs to interact with them. For example mount.

You can use the system binary mount in the /bin folder to interact with a removable hard drive for example.

lost+found

If you have a system crash and the Linux file system checker (fsck) recovers corrupt files they are placed here.

opt

Opt is reserved for additional software you install; although, most providers don’t use it. This is kind of like ‘Program Files’ for linux.

sbin

Sbin is similar to /bin with the exception that these ready to run binaries are reserved for root users. That is they typically will only work when executed by root or sudo. Examples would include:

tmp

Tmp is a temporary storage folder. Anything that is to be temporarily stored goes here. It is recommended that you don’t delete these manually. If you want to delete them you usually add this to boot up or shutdown procedure since they can contain useful information for programs that are already running.

boot

This folder contains only the files that are absolutely necessary to get a basic Linux system up and going. This folder is not used for programs to run on startup or other user scripts. This folder usually contains Grub information and the Linux kernel.

etc

This folder is the config folder for your entire operating system. Almost everything about configuring your system can be done in here. The general rule of thumb is that these files are static and text based. No binaries should be placed in this folder.

Common config files in here are:

Media

Traditionally all mounts were stored in the /mnt directory but out of controversy of where to stored removable mounts this directory was born. /media should be used to store mounts for removable devices only, like:

proc

Proc is a special virtual directory like /dev that contains process information. It contains runtime system info like: system memory, devices mounted, hardware configuration, etc.

srv

Srv is a serve folder. It holds site specific data to be served by the system for protocols such as, ftp, rsync, www, cvs etc. To be compliant distributions include this folder but I have not seen it used much.

usr

Usr houses all the binaries, documentation, libraries, and header files for all the user applications. Most user binaries will be installed into this folder making this one of the largest folders in the Linux directory.

cdrom

CD-Roms can be mounted to this folder but it is not in the official Linux Filesystem Hierarchy. CD-Roms should be mounted under /media.

home

Home is where you will store all user specific documents and settings. This is similar to Windows, “Documents and Settings”. On most Linux distributions /home will contain a directory with each user’s name or group of users. e.g. /home/mark /home/guests.

lib

Lib contains system library binaries that are required to run the system. In Windows this would be the system folder with .dlls. Only in Linux it is represented by ‘.so’.

mnt

According to FSSTND version 2.3, “ This directory is provided so that the system administrator may temporarily mount a filesystem as needed. The content of this directory is a local issue and should not affect the manner in which any program is run.”

I think of this directory as the place to mount fixed hard drives that I mount with the fstab file, but as described in FSSTND it is primarily for temporary mounts.

root

Root is the “home” directory for root. If this directory doesn’t exist it defaults back to ‘/’. Hence the username root.

sys

This is kinda like /proc it is used for plug and play configuration.

var

This stands for variable. This stores all the files that vary as the system runs. Things like log files, backups, mail, cache, etc..

Conclusion

So there you have it a quick layout of the Linux system. If you have any further questions you can consult the official Filesystem Hierarchy Standard (FHS) or comment below.

comments powered by Disqus