Linux Filesystem Exposed
Prepare yourself… I am about to reveal the naked truth. You see, I like exposing things. All sorts of things. And here’s one of them. As a newcomer to the Linux OS, you’re going to find things can be quite tricky and hard going…until you figure out the Linux filesystem, that is. Admit it, you were expecting me to say something else, weren’t you? You cheeky monkey, you!
During my time on this planet, I have come across many people who found Linux to be confusing and almost alien-like right from the start, mainly because of its complicated hierarchy of files and folders. Well, newbie…first of all, welcome aboard the Linux Ship Enterprise, and second, I’m amazing. Why? Because I’m going to give you the crib-sheet guide on the Linux Filesystem that you’ve been waiting for most of your adult life.
I’m only going to give you the "reader’s digest" version here so you can be up and running quickly. Plus, I have always been a fan of pithiness, and pickles.
So, here she be…
The Linux Filesystem Hierarchy
First, let me point out that on Linux, there is only a single hierarchical directory structure. Everything starts from the root directory, represented by ‘/’, and then expands into sub-directories. Where DOS/Windows had various partitions and then directories under these partitions, Linux places all the partitions under the root directory by ‘mounting’ them under specific directories. The closest to root under Windows would be c:.
Also, under Windows, the various partitions are detected at boot and assigned a drive letter. But under Linux, unless you mount a partition or a device, the system does not know about the existence of that partition or device. This might not seem to be the easiest way to provide access to your partitions or devices, but it offers great flexibility and power. Which, let’s face it, is what we all want in the end.
This kind of layout, known as the unified filesystem, does offer several advantages over Windows’ approach. Let’s take the example of the /usr directory. This directory off the root directory contains many of the system’s executables. With the Linux filesystem, you can choose to mount it off another partition or even off another machine on your network. The underlying system will not know the difference because /usr appears to be a local directory that is part of the local directory structure! How many times have you wished to move executables and data around in Windows, only to run into registry and system errors? Try moving c:/windows/system32 to another partition or drive. It will fail miserably and you will cry.
Linux has a filesystem hierarchy that is pretty typical amongst the various flavors and distributions of Linux. There are some minor differences here and there, so let’s take a look at a few of the most common ones:
Note: Before beginning, please understand that it is quite easy to confuse “root” as in the user and “root” as in the root directory. The two are indeed separate entities; the root directory is “/”, the root user is “root”. When I say "root" I am actually referring to the root directory.
- / - is referred to as the “root” of the filesystem. It is the trunk of the file tree and the starting point of the filesystem. Every other file or directory is subordinate to “/”. If you type "cd /" at the Terminal, you are now at the root of the filesystem.
- /root - not to be confused with “root”, rather, it is usually the home directory for the root user (remember the note above). This is the most powerful user on your system. This directory also typically contains installation logs and a few scripts used by the system administrator.
- /bin - This is where the essential user binaries are stored for both admin and common users. Commands and/or Programs such as “ls”, “cat” and “mv” and all the shells like bash, ksh, csh etc. would be found in this directory.
- /sbin - This is where the essential binaries used for system administration, and by the system itself, would be found.
- /dev - This is a very interesting directory. It highlights one important characteristic of the Linux filesystem - that everything in Linux is a file or a directory. Look through this directory and you should see sda1, sda2, etc., which represent the various partitions on the first master drive of the system. /dev/cdrom and /dev/fd0 represent your CDROM drive and your floppy drive. This may seem strange but it will make sense if you compare the characteristics of files to that of your hardware. Both can be read from and written to. Take /dev/dsp, for instance. This file represents your speaker device. So any data written to this file will be re-directed to your speaker. Try typing this at the Terminal, cat /etc/fstab > /dev/dsp and you should hear sound coming out of your PC speaker. That’s the sound of your fstab file. Oh, isn’t this is a wacky world we live in?
- /lib - This is where shared libraries, that are needed by binaries in the “/bin” and “/sbin”, are stored.
- /boot - This is where the boot loader (from the MBR) looks to load the kernel. This comes before any other partition is mounted or any user mode.
- /lost+found - Linux should always go through a proper shutdown. Sometimes your system might crash or a power failure might take the machine down. Either way, at the next boot, a lengthy filesystem check using fsck will be done. Fsck will go through the system and try to recover any corrupt files that it finds. The result of this recovery operation will be placed in this directory. The recovered files are not likely to be complete or make much sense but there is always a chance that something worthwhile was saved. Like your recipe for quiche. I mean, beer.
- /mnt - This is a generic mount point under which you mount your filesystems or devices. You are free to mount your drives anywhere (just not in public, please). Here is a good and sensible location to do it.
- /etc - This is an acronym for… well, actually no one agrees on what it stands for. I always call it "et-C", but some people seem to think it stands for et cetera. It is basically where most of the configuration files for your system would be found. More importantly, the /etc/rc.d directory contains the system startup scripts. This is a good directory to back up often.
- /var - This directory contains spooling data like mail, and also the output from the printer daemon. All the system logs are kept here in /var/log, as well.
- /tmp - This directory contains mostly files that are required temporarily. Many programs use this directory to create lock files and for temporary storage of data.
- /proc - The most striking factor about the /proc file system is the fact that the file system doesn’t exist on any particular media. The /proc File System is a pseudo file system residing in the virtual memory and maintains highly dynamic data on the state of your operating system. Most of the information in the /proc file system is updated to match the current state of the running operating system. The contents of the /proc file system can be read by anyone who has the requisite permissions. However, certain parts of the /proc file system can be read only by the owner of the process and root (a.k.a. God).
- /opt - This directory may contain software and add-on packages that are not part of the default installation. This directory is not used very often, though, as it’s mostly a standard in Unix installations.
- /home - Linux is a multi-user environment. This is where the user account directories are found. Typically, each user has a directory in the “/home” directory where they have control over it, and whatever may be beneath it. Also, user specific configurations may be stored in its sub structure.
- /usr - contains the subdirectories “/usr/bin”, “/usr/sbin,” and “/usr/lib” which perform similar functions as “/bin”, “/sbin”, and “/lib”, but are not needed at boot time. Many non-essential user and system binaries are stored here. The directory “/usr” also contains most of the documentation for the binaries and libraries on your system.
Well, that completes our basic look at the Linux filesystem. What have we learned, boys and girls? You have learned what true power and beauty look like (rather like me, actually).
Now take what you have learned and tell your friends. In fact, tell your enemies, too, in a taunting manner, of course. They will become jealous and want to know what you know. Teach them (after some more taunting). We must get every Tom, Dick and Harriet to live, breath and love Linux! After that, we will rule the world!
Until then…carry on.

Articles 







Hi there,
what about an article on how to install a whole functional and bootable linux (maybe Debian?) into a usb thumbdrive
that would certainly impress many new comers, livecds and now usbs
Hi Mic!
This may sound crazy, but that is exactly one of the current articles I am working on. It will be released in the next week or so. Thanks for your comment!
I found your blog via Google looks very interesting to me. I always enjoy coming to this site because you offer great tips and advice for people like me who can always use a few good pointers. I will be getting my friends to pop around fairly soon.
Excellent review of the file system. I enjoyed reading it and found it to be a great refresher. Linux rules!
Thanks Ken! I am glad you liked it. You are my new best friend.