What is the Structure of Linux?

Article by Tolga BALCI (23,398 pts ) , published Apr 8, 2009

Have you ever wondered what is the structure of Linux? What are these /etc, /opt, /lib folders? Hop right in to go through each one in detail.

Introduction

After a fresh install of Windows XP, you have three typical folders: Documents and Settings, Program Files and Windows. As we all know, Documents and Settings folder is where we save our files and where Windows keeps our personal settings, Program Files folder is where installed programs go to and Windows is the operating system’s own directory.

Linux, as in all computer operating systems, has its own files and folders. There are more than three folders and a very strict file/folder hierarchy defined by the Linux Standards Base. For example, the root directory, denoted with / is the parent of all the system; all other folders are children of root. The /home folder is similar to Documents and Settings, which keeps the files and preferences of the individual users. Each user’s folder is a child of the parent /home folder. There is one thing to note here, there is also a /root folder, which is the home directory of the root user.

As you have already figured out, Linux uses / (slash) in folder names, whereas Windows uses a \ (backslash.) [Ed: Windows allows the use of either the forward or back slash when designating directories at the command prompt.]

/mnt

I have to talk a little bit about mounting and the /mnt directory at first because I will use the word heavily in the article. I will describe this in detail later on in the article but for the time being just know that Linux treats all devices (I mean all devices such as hard disks, CDs, sound cards, printers and the like) as files. Mounting is a process which you make a device available for the system. For example when you plug a 2 GB USB stick, Linux looks at it and says “Hmm, this is an X brand external storage device, having 2 gigabytes of capacity, plugged in to the USB port and has a FAT32 filesystem. OK, I understood it, I can read and write files to/from it.”, in other words, Linux “mounts” it.

Linux mounts all the devices, be it the filesystem or the hardware, under the /mnt directory. You can also mount folders/devices manually. For example, assume that you have a secondary hard disk, which is recognized as /dev/sdb1 in your system. You can mount this hard disk by issuing mount /dev/sdb1 /home/yourusername/newdisk command as root. After that you can access your disk by simply changing to the newdisk folder under your home directory.

/bin

This folder contains the essential commands that both system administrators and regular users use to work with the computer. In most of the distributions the shells (bash, sh, tcsh, zsh etc.) are also contained in this folder. The commands that are in /bin directory are cp (copy), mv (move), login, chgrp (change group), chmod (change file access permissions), chown (change file/folder ownership), date (displays system time), ps (view status of the processes) and others such as dd, df, hostname, kill, dd, su. You can have a look at the /bin contents by issuing ls /bin from the command line.

The commands are considered essential because even in single user mode (for more information about user modes or runlevels, you can check How Linux Works article) you are able to use the commands.