Linux File System Overview, a very basic look

Posted by sudhirmangla July 4, 2008

"This Linux file system is crazy…"

This FAQ is a quick overview that I have written to summarize how the files are generally organized into their directories. I have often described this, in the past, as looking at a vertical vs. horizontal method of determining where different files should be placed. blink.gif However, that doesn’t really clear things up for 99% of the people I have tried to describe this to, so I will attempt to better explain this here. I will cover the file & directory organization in very broad brush strokes. For more detailed information, there are thousands of in-depth resources to be found with a brief Google. Most Linux books cover this as well (but are often skipped as they aren’t readily understood by most people who haven’t worked with Linux for a while).

Half Full Glasses and Photos

The first thing (or one of the first things, anyhow) that a Windows user who has moved to Linux (or any Unix-like OS) must shed is the belief of How Things Should Be. Just because one OS does things a certain way, doesn’t mean that any other way is ‘wrong’. Like whether you consider a glass to be half-empty or half-full, it is a matter of perspective.

Consider this to be like your digital family photos on your computer. You may keep your files organized by year (2003, 2004, 2005, etc.) and keep the sets of photos belonging to the separate events (Michael’s Birthday or Joshua’s Football Game) in their own folders inside each year. It is a convenient way to see all the events of each year, plainly organized in front of you when you open that 2004 folder.

But, that isn’t the only way that photos can be organized. If you want to go to all of the "Summer Vacation" photos and reminisce about the all family vacation fun you have had, you will find them scattered into all the various year folders. This brings up another way photos can be organized: by subject. This can be done on your family photos, so that all the Birthdays that Timothy has had through the years can be found in their own specific folder. Modeling agencies would almost have to sort by model name, not by year of photo.

Windows and Linux Directories

What that talk about photos have to do with Linux file organization? Quite a bit, actually.
Windows organizes installed applications by their own folder in "My Programs". Each app creates a folder for everything to go into. This may sound extremely neat, but Windows really isn’t as neatly organized as the that made it sound. It scatters .dll files around to different folders and modifies the registry, too. Try copying an app by moving the "Program Files" folder to a new computer, and it won’t function.

Linux, on the other hand, puts all "executables" (or "binaries") into a bin/ directory. You won’t find the man pages (help files) in there, as those are placed in the man/ directory. Any source code you have on your system will be in a src/ directory. It’s a different way of seeing how a file system should be organized, and quite often it seems counter-intuitive to a Windows user.

Ok, Why so Many?

While the concept of bin/ may be easy enough to understand, Windows users will next run into the many different bin/ directories (and sbin/, for system binaries that are usually reserved for users with elevated privileges). Often this will be the next big stumbling block. After all, it just seemed to make sense - then they find that there is no "one place" for these binaries.

This is understood when you really accept that Unix has been a multi-user system for quite a long time (longer than Windows has been around!), and its filesystem reflects this. Different conventions exist, and the following is not a fact for all systems, but is meant to illustrate by example:

  • The basic OS installs what it needs in /bin/. Everyone needs to have access to these basic functions.
  • The distro will often install and additional apps it uses into /usr/bin/. Again, all users may have access to this.
  • Add-ons may be installed into /usr/local/bin/, as these files are local to the machine you are working on, and may not exist on another PC, even if installed with the same version.
  • Users without write/execute permissions outside their home directory may use /home/username/bin/, so they can have their own executables that are unique to them (perhaps they are learning C and making test programs).

To see what your particular system is set to look for any binaries you ask it to run, perform an

 

echo $PATH

to see what directories it uses.
File Extensions…

This is another piece of baggage from the days of DOS, and even Windows attaches great significance to a file extension. In particular, the whole .exe thing is thrown away in Linux. Not only a compiled binary file, but any file may be made "executable" by setting the proper file attribute (either via chmod at the command line, or by mouse click on Properties using the more advanced file managers available with Gnome or KDE). A text file can be made executable, which is then interpreted like a DOS .bat "batch file".

Hidden Files

Files in Unix don’t have a "hidden" attribute. A file (or directory) is considered hidden when you start the filename with a dot. For example, the file .bash_history (which contains the last several hundred commands you have issued at the bash prompt) in your home folder is not shown by a plain ls command. If you wish to see the hidden files, you can use ls -a to display all files.

Almost Everything is a File!

Or, if not a file, then it is represented in the Linux file system. Your devices are all in the /dev/ folder. Various system and kernel information is represented (and can be set!) in the /proc/ directory. An interesting task is to do a cat /proc/cpuinfo and look what Linux tells you about your CPU.

The Forward Slash: The ‘root’ of all Goodness

Unlike what a DOS/Windows user is used to, drives (or, more accurately, partitions are not set up each as separate "tops" of the file tree. There is no C:\filename.ext with no file system above. All partitions that are mounted are assigned to a folder (typically in the /mnt/ directory). Unix and all variants use the forward slash ‘/’ as the starting point for all file references, regardless of which drive, network attachment, or device you are referring to. There is no need to care whether /home/, /boot/, /mnt/cdrom or /mnt/windows_c are on your "Linux drive", or if they are elsewhere. Even devices such as scanners are found in the file tree. It can be a strange concept when you first migrate to Linux, but it makes sense when you become used to it.
More awaits you…

Alas, I will end this here. This little FAQ just touched on the filesystem that Linux (and other Unix variants) use to keep things organized. It may seem totally foreign at first, but once you get used to thinking the *nix way, things do get easier.

In closing, I would like to invite anyone else that wants to add to this with some additional detail or information that I did not cover, please post this information as an "addendum" to this first post. Or, if you feel particularly energetic, write your own short HOWTO or FAQ for the Linux section.

Related Posts

Categories : Linux  Tags : , ,

Got something to say?