Wednesday, February 15, 2006

Basic FileSystem in Linux

While switching from windows to linux you will notice a very different kind of filesystem in Linux.

No Partion in Linux
In windows you have various partitions like c:, d:, e: like that and then we save our directories/files in thaose partitions.But in Linux we have only one partition called ROOT (denoted as '/'). Linux places everything in that root partition.

Mounting in Linux
You might be thinking that how do we access windows partition from linux when we have only one partition. Ofcourse you can access. You just have to mount the various partitions into root directory (I will explain it soon).
Widows detect various partition during booting but in linux we need to mount all those partition then only it can be accessed. Today almost all the linux detect partition during booting and mount them but if you add some more partition after installation of linux you need to do that manually.

One very important difference is that linux is "CASE SENSITIVE" but windows don't. Like if you have to access a directory of name "Movies" in /usr/home then you need to write /usr/home/Movies not /usr/home/movies. It wont work in linux. But windows is not case sensitive so it's fine with it.

Now come to the file structures:

You can see all the directories in '/' by typing 'ls' or 'ls -p' or 'ls -l'
sk / $ ls
bin dev home mnt proc sbin sys usr windows
boot etc lib opt root suse tmp var
sk / # ls -l
total 23
drwxr-xr-x 2 root root 3472 Jan 3 20:47 bin
drwxr-xr-x 4 root root 1024 Feb 8 07:28 boot
drwxr-xr-x 19 root root 30600 Feb 13 22:19 dev
drwxr-xr-x 60 root root 3672 Feb 13 22:19 etc
drwxr-xr-x 4 root root 120 Oct 5 19:18 home
drwxr-xr-x 7 root root 3840 Jan 3 20:41 lib
drwxrwxrwx 4 root root 120 Jul 26 2005 mnt
drwxr-xr-x 6 root root 200 Jan 19 15:41 opt
dr-xr-xr-x 95 root root 0 Feb 13 22:18 proc
drwx------ 17 root root 1168 Feb 15 23:29 root
drwxr-xr-x 2 root root 3864 Jan 3 20:47 sbin
drwxr-xr-x 23 root root 560 Feb 8 07:32 suse
drwxr-xr-x 10 root root 0 Feb 13 22:18 sys
drwxrwxrwt 33 root root 7360 Feb 15 23:28 tmp
drwxr-xr-x 15 root root 464 Oct 4 10:12 usr
drwxr-xr-x 13 root root 360 Feb 6 07:24 var
drwxrwxrwx 8 root root 192 Oct 4 18:56 windows

//Write up source : by Mayank Sarup

Lets describe each filesystem:

/sbin/ -
==> Contains all the system binaries that are required to run OS.
==> This includes : Maninatainace hardaware configuration,system programs.
==> There is also a "/usr/sbin/" : Contains other binaries of system admin like network daemon but binaries are not used by system admin for mainatainace,rapair.

/bin/ -
==> Contains all the commands used by both system admin and users.For example: cp, mv, cat, rm etc
==> There is also a /usr/bin/: It contains all user binaries.

/boot/ -
==> Contains the file as well as the Linux kernel.
==> Grub/lilo configuration files is also there.Lilo places the boot sector backups in this directory.

/dev/ -
==> This is a very interesting directory that highlights one important characteristic of the Linux filesystem - everything is a file or a directory. Look through this directory and you should see hda1, hda2 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 'cat /etc/lilo.conf > /dev/dsp' and you should hear some sound on the speaker. That's the sound of your lilo.conf file! Similarly, sending data to and reading from /dev/ttyS0 ( COM 1 ) will allow you to communicate with a device attached there - your modem.

/etc/ -
==> This directory contains all the configuration files for your system.
==> Your lilo.conf file lies in this directory as does hosts, resolv.conf and fstab.
==> Under this directory will be X11 sub-directory which contains the
configuration files for X.
==> More importantly, the /etc/rc.d directory contains the system startup scripts. This is a good directory to backup often. It will definitely save you a lot of re-configuration later if you re-install or lose your current installation.

/home/ -
==> Linux is a multi-user environment so each user is also assigned a specific directory which is accessible only to them and the system administrator. These are the user home directories, which can be found under /home/username. This directory also contains the user specific settings for programs like gaim,firefox, etc
==> This is same as we have different users in windows.

/lib/ -
==> This contains all the shared libraries that are required by system programs. Windows equivalent to a shared library would be a DLL file.

/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 files recovered are not likely to be complete or make much sense but there always is a chance that something worthwhile is recovered.

/mnt/ -
==> This is a generic mount point under which you mount your filesystems or devices. Mounting is the process by which you make a filesystem available to the system. After mounting your files will be accessible under the mount-point. This directory usually contains mount points or sub-directories where you mount your floppy and your CD. You can also create additional mount-points here if you want. There is no limitation to creating a mount-point anywhere on your system but convention says that you do not litter your file system with mount-points.

/opt/ -
==> This directory contains all the software and add-on packages that are not part of the default installation. Generally you will find KDE and StarOffice here. Again, this directory is not used very often as it's mostly a standard in Unix installations.

/proc/ -
==> The /proc directory contains virtual files that are windows into the current state of the running Linux kernel. This allows the user to peer into a vast array of information, effectively providing them with the kernel's point-of-view within the system. In addition, the user can use the /proc directory to communicate particular configuration changes to the kernel.
==>Viewing Virtual Files :
$cat cat /proc/iomem
$cat /proc/cpuinfo

/root/ -
==> We talked about user home directories earlier and well this one is the home directory of the user root. This is not to be confused with the system root, which is directory at the highest level in the filesystem.

/tmp/ -
==> This directory contains mostly files that are required temporarily. Many programs use this to create lock files and for temporary storage of data. On some systems, this directory is cleared out at boot or at shutdown.

/usr/ -
==> This is one of the most important directories in the system as it contains all the user binaries. X and its supporting libraries can be found here. User programs like telnet, ftp etc are also placed here. /usr/doc contains useful system documentation. /usr/src/linux contains the source code for the Linux kernel.

/var/ -
==> This directory contains spooling data like mail and also the output from the printer daemon. The system logs are also kept here in /var/log/messages. You will also find the database for BIND in /var/named and for NIS in /var/yp.

You can mail me personally at and can visit website which is daily updated by me or


Post a Comment

Links to this post:

Create a Link

<< Home