Understanding the Linux Directory LayoutThu, Feb 5, 2009
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:
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:
cp - Copy files to and from
ls - Get a directory listing, remember we used this above
bash - A popular Linux CLI (shell)
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.
If you have a system crash and the Linux file system checker (fsck) recovers corrupt files they are placed here.
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 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 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.
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.
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:
/etc/X11 - For configuring X (gui)
/etc/apt/sources.list - Configuring apt for Debian based systems
/etc/cups - Printer configuration
/etc/fstab - Device mounting
/etc/httpd - Apache webserver
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 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 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 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.
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 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 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’.
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 is the “home” directory for root. If this directory doesn’t exist it defaults back to ‘/’. Hence the username root.
This is kinda like /proc it is used for plug and play configuration.
This stands for variable. This stores all the files that vary as the system runs. Things like log files, backups, mail, cache, etc..
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.