Directory structures and system layout
From Linux 101, The beginner's guide to all things Linux.
Contents |
[edit] Introduction
In Windows, you're used to seeing things like A-drive, C-Drive, D-drive, and so forth. Windows recognizes physical hardware locations and partitions as different drives. Linux, however, handles them quite differently.
Linux uses the Filesystem Hierarchy Standard (FHS), which is a organized layout of all files and directories used by UNIX and its clones. Everything is stored in one big tree-like structure. At the base is the /, or root directory (sometimes refered to as the root—please do not confuse this with the root user, these are two different ideas). All other directories branch out of the root directory.
When hard drive partitions, CD-ROM's, and floppies are mounted, they are assigned particular directories. These are called mount points. Mount points are usually in the /mnt directory. Here's a basic example:
| Mounting Device | To |
| /dev/hda1 | / |
| /dev/cdrom | /mnt/cdrom |
This configuration tells Linux that if you try to read/write to any directory other than /mnt/cdrom or the subdirectories of /mnt/cdrom, that it should put the files on (or get the files from) /dev/hda1, which is our first hard drive's first partition.
[edit] Basic Directory Layout
/bin
/boot
/dev
/etc
/home
/lib
/mnt
/opt (not all distributions will have this)
/proc
/root
/sbin
/sys (not all distributions will have this)
/tmp
/usr
/var
[edit] The Purpose of the Directories
In windows, when you install a program, you're used to it installing it into a new directory. Everything from configuration to executables are placed in the same folder. This is convenient when you want to delete the program from the system, but more generally, this could be considered a security flaw. So, Linux introduced a different scheme -- the one above, and here's how it breaks down:
- /bin
- is where system executables go. Take note here: system executables -- not user programs. Basic programs for compression or shell script execution go here. Roughly speaking, you may see 150 programs in here.
- /boot
- contains all the programs and information needed to start Linux. It is best for boot to be a separate partition from the rest of the system, so in case some corruption occurs to your / partition, /boot will be unaffected and you will still be able to start your system. The actual linux kernel will be placed in this directory. GRUB or LILO bootloader configuration also usually goes here.
- /dev
- can be an overwhelming directory at first. The important thing about how linux works is that for every piece of hardware on your computer, there is a /dev entry. This includes harddrives/floppies/clocks/video/memory -- the works. Also some less-than-physical devices, such as terminals have entries in here. Each entry is represented as a file, and most are sorted logically into directories.
- /etc
- is your system configuration folder. Configurations for programs that will be run by more than one user go here. Any user can browse /etc, so feel free to just look around and see what is in yours.
- /home
- is where users store their files. In Linux, except for the root user, no one else is allowed to write outside of /home by default (with the exception of /tmp). This is a great security measure, since unlike windows, some random program cannot write all over your computer and hide things from you. It is a good strategy to put /home on a different partition on your computer, so if anything breaks you can reinstall linux without losing your personal files!
- /lib
- is a system folder, and unless you're a software developer, it will be of little interest to you to edit files in it. Doing so can cause serious trouble to your computer.
- /lost+found
- is a directory that is used by a filesystem checker to store lost file fragments in. It is usually empty.
- /mnt
- is your mount directory. If you're planning on having temporary mount points (cdroms/floppies/extra harddrives/network mounts) then this is where you should place them. Some systems use /media instead of /mnt.
- /opt
- is usually for large packages. Java, games, and office suites usually make this their home.
- /proc
- is a very useful folder. It will tell you what the kernel knows about your system, from hardware to programs running, and more.
- /root
- is the home directory for the root user. It's placed here instead of /home
- /sbin
- is the superuser binaries folder. So only the root user will be able to execute these programs.
- /sys
- is similar to the /proc folder for the kernel 2.6
- /tmp
- is your temporary files folder. Various different software programs will put work here for temporary measure.
- /usr
- is your user resources. Any program you install on your computer should be placed into here for good measure. Underneath /usr there is another directory tree, like:
- /usr/bin
- /usr/lib
- /usr/sbin
- and so forth. These folders follow the same pattern as the ones above. It is also good to note here that there are a lot more directories under /usr, for example: /usr/include, /usr/man, and /usr/share. You may browse all of these files to really look around your system and see what is installed. Depending on how much you store in /home, /usr is probably the largest directory on your entire system.
- /usr/local
- This is the default place where files are installed from programs that are locally compiled from source. Also programs that are not installed through your distribution's package system sometimes install here (depending on the distribution and package system, if any). This directory has the subdirectories lib, bin and sbin, which are comparable to the /usr/lib, /usr/bin, /usr/sbin directories.
- /var
- is for files that can vary often. System logs, mail spools, and the like are usually found here.
[edit] Summary Notes
This design is really nice because it allows you to use the mountpoints scheme. The true benefit to the mountpoints scheme is that Linux deals with the behind the scenes file writes and reads. So you may be running a program to write a file into /home/youraccount, /mnt/floppy, and /mnt/networkdrive but the program would not know the difference between any of these, because the Linux kernel takes care of all the dirty work for you.
A succinct summary of the first level directories as well as other common Linux directories are available as a man page. Just issue the command
-
man hier
at the console. The man page follows a standard so it is not guaranteed to be exactly like your host distribution, but chances are it will be close.

