Linux basics - Linux file system structure overview

Linux file system structure overview is an introduction to file system directory hierarchy in Linux system. A Linux beginner might get confuse between Linux file system structure and Linux filesystem type. Maybe you still remember during Linux hard disk partition process, we have to choose Linux filesystem type which includes ext2, ext3, reiserfs, etc. That's Linux filesystem type. What we are going to learn in this tutorial is Linux file system structure, a system directory hierarchy that has been derived from Unix.

In Windows operating system, we have C:\ drive, and there are many directories under C:\, such as Documents and Settings, Program Files, etc. In Linux, we can think of / (root directory) as C drive in Windows. All file system directory or mount points in Linux are under / directory.

It maybe strange looking at Linux file system structure at first. There are many directories full of child directories and files. Some directories such as bin, sbin and lib can be found in several other directories too.

Calm down. Actually, Linux file system is not so complicated as you might think. I already mentioned about root directory (/) which contains all other directories in Linux system. Now let's see it for ourselves.

Change to / directory by typing 'cd /'. Type 'ls' to view the content.

This is a Slackware Linux file system structure:

luzar@musang:~$ cd / 
luzar@musang:/$ ls
bin/   dev/  home/  lost+found/  mnt/  proc/  sbin/  sys/  usr/
boot/  etc/  lib/   media/       opt/  root/  srv/   tmp/  var/ 
luzar@musang:/$

This is Ubuntu Linux file system directory:

luzar@ubuntu:/$ cd / 
luzar@ubuntu:/$ ls 
bin   cdrom  etc   initrd      lib         media  opt   root  srv  tmp  var
boot  dev    home  initrd.img  lost+found  mnt    proc  sbin  sys  usr  vmlinuz 
luzar@ubuntu:/$

In Linux, we use ls command to lists or views directory content. To view long listing of the content, type 'ls -l' and Enter.

Example of Slackware Linux file system directory viewed using ls command long listing option:

      
luzar@musang:/$ ls -l 
total 72
drwxr-xr-x   2 root root  4096 2007-04-30 12:35 bin/
drwxr-xr-x   2 root root  4096 2008-09-06 08:40 boot/
drwxr-xr-x  17 root root 14220 2008-11-01 16:55 dev/
drwxr-xr-x  65 root root  4096 2008-11-01 16:54 etc/
drwxr-xr-x   4 root root  4096 2008-11-01 16:54 home/
drwxr-xr-x   5 root root  4096 2008-03-12 11:47 lib/
drwx------   2 root root 16384 2008-09-06 08:19 lost+found/
drwxr-xr-x  16 root root  4096 2008-11-01 16:53 media/
drwxr-xr-x  11 root root  4096 2008-09-20 23:03 mnt/
drwxr-xr-x   2 root root  4096 2007-06-10 14:23 opt/
dr-xr-xr-x 107 root root     0 2008-11-02 00:52 proc/
drwxr-xr-x  11 root root  4096 2008-10-18 09:30 root/
drwxr-xr-x   2 root root  4096 2008-11-01 16:53 sbin/
drwxr-xr-x   2 root root  4096 2008-09-06 08:29 srv/
drwxr-xr-x  12 root root     0 2008-11-02 00:52 sys/
drwxrwxrwt  21 root root  4096 2008-11-01 16:56 tmp/
drwxr-xr-x  17 root root  4096 2006-11-09 04:10 usr/
drwxr-xr-x  17 root root  4096 2006-11-09 04:10 var/
luzar@musang:/$

We can see details such as permissions, owner and date. Don't worry about any of these now. We are going to learn all of them later.

Example of Ubuntu Linux file system directory:

luzar@ubuntu:/$ ls -l 
total 84
drwxr-xr-x  2 root root  4096 2008-11-20 03:41 bin
drwxr-xr-x  3 root root  4096 2008-11-06 02:47 boot
lrwxrwxrwx  1 root root    11 2008-10-20 10:44 cdrom -> media/cdrom
drwxr-xr-x 12 root root 13880 2008-12-03 21:46 dev
drwxr-xr-x 81 root root  4096 2008-12-03 22:15 etc
drwxr-xr-x  6 root root  4096 2008-10-24 00:07 home
drwxr-xr-x  2 root root  4096 2008-10-20 10:45 initrd
lrwxrwxrwx  1 root root    32 2008-10-20 10:46 initrd.img -> boot/initrd.img-2.6.24-19-server
drwxr-xr-x 13 root root 12288 2008-11-20 03:41 lib
drwx------  2 root root 16384 2008-10-20 10:44 lost+found
drwxr-xr-x  4 root root  4096 2008-10-20 10:44 media
drwxr-xr-x  3 root root  4096 2008-11-03 03:01 mnt
drwxr-xr-x  2 root root  4096 2008-10-20 10:45 opt
dr-xr-xr-x 86 root root     0 2008-12-03 21:45 proc
drwxr-xr-x  3 root root  4096 2008-10-20 06:05 root
drwxr-xr-x  2 root root  4096 2008-11-20 03:41 sbin
drwxr-xr-x  2 root root  4096 2008-10-20 10:45 srv
drwxr-xr-x 12 root root     0 2008-12-03 21:45 sys
drwxrwxrwt  3 root root  4096 2008-12-03 21:46 tmp
drwxr-xr-x 10 root root  4096 2008-10-20 10:45 usr
drwxr-xr-x 14 root root  4096 2008-10-20 10:55 var
lrwxrwxrwx  1 root root    29 2008-10-20 10:46 vmlinuz -> boot/vmlinuz-2.6.24-19-server
luzar@ubuntu:/$

If we want to draw a directory tree of the Linux system directory, it looks like this:

Linux file system directory tree

Some file system structure and directories in one Linux distribution maybe different from other Linux distributions as you can see from Slackware and Ubuntu example above. Right now you don't have to remember all of these directories and what they do. Just remember a few important directories first such as:

  • / - root of all directories in Linux file system structure.
  • /home - Keeps Linux user account's home directory.
  • /etc - keeps Linux server's configuration files and directories.
  • /usr - keeps Linux system files.
  • /var - keeps system log files.
  • /bin - keeps binary files for user applications.
  • /sbin - keeps static binary files for system programs.

The / (root) directory is the most important directory in Linux file system structure. As you can see from the example above, / is the root of all directories in Linux system. The / is the parent of Linux file system structure.

The /home directory keeps all Linux user account's home directory. Some Linux distributions keep FTP server home directory by default in /home directory. Make sure you provide big enough hard disk for /home directory. It's a good idea to set quota for each user account in /home directory.

The /etc directory keeps all servers and application system's configuration files. This directory perhaps the most visited directory if you are working in Linux command line terminal.

This is an example of Linux file system structure of Ubuntu /etc directory:

luzar@ubuntu:~$ cd /etc 
luzar@ubuntu:/etc$ ls -d */ 
alternatives/       depmod.d/             modprobe.d/  rc6.d/
apache2/            dhcp3/                Muttrc.d/    rcS.d/
apm/                dictionaries-common/  mysql/       resolvconf/
apparmor/           dovecot/              network/     samba/
apparmor.d/         dpkg/                 openoffice/  sane.d/
apt/                emacs/                opt/         security/
bash_completion.d/  event.d/              pam.d/       skel/
belocs/             fonts/                pcmcia/      snort/
bind/               foomatic/             perl/        ssh/
calendar/           groff/                php5/        ssl/
chatscripts/        grub.d/               postfix/     subversion/
console-setup/      hp/                   ppp/         terminfo/
console-tools/      init.d/               prelude/     udev/
cron.d/             initramfs-tools/      profile.d/   ufw/
cron.daily/         iproute2/             python/      update-manager/
cron.hourly/        john/                 python2.5/   vim/
cron.monthly/       ldap/                 rc0.d/       w3m/
cron.weekly/        ld.so.conf.d/         rc1.d/       whereami/
cups/               libpaper.d/           rc2.d/       wpa_supplicant/
dbus-1/             logcheck/             rc3.d/       X11/
default/            logrotate.d/          rc4.d/
defoma/             lsb-base/             rc5.d/
luzar@ubuntu:/etc$

When listing directory content in Linux system, other than directories, there are normal files, executable files and symbolic links. How to differentiate each of them?The subject in blue color is a directory. It always mark with a '/' as in the example above. Sometimes you'll find a subject in green, light blue and white color. The green subject (mark with *) is an executable file. The light blue subject (mark with @) is a symbolic link and the white subject is a file.

Type 'cd /etc/rc.d' and Enter. Type 'ls' to view the content.

      
luzar@musang:/usr$  cd /etc/rc.d/ 
luzar@musang:/etc/rc.d$ ls 
init.d/    rc.bluetooth       rc.inet2*                 rc.pcmcia     rc.wireless*
rc.0@      rc.bluetooth.conf  rc.inetd*                 rc.rpc        rc.wireless.conf
rc.4*      rc.cups            rc.ip_forward             rc.samba      rc.yp*
rc.6*      rc.dnsmasq         rc.local*                 rc.saslauthd  rc0.d/
rc.K*      rc.font.new*       rc.messagebus*            rc.sendmail   rc1.d/
rc.M*      rc.fuse*           rc.modules@               rc.serial     rc2.d/
rc.S*      rc.gpm*            rc.modules-2.6.24.5*      rc.snmpd      rc3.d/
rc.acpid*  rc.hald*           rc.modules-2.6.24.5-smp*  rc.sshd*      rc4.d/
rc.alsa*   rc.httpd           rc.mysqld                 rc.syslog*    rc5.d/
rc.atalk   rc.inet1*          rc.nfsd                   rc.sysvinit*  rc6.d/
rc.bind    rc.inet1.conf      rc.ntpd                   rc.udev*
luzar@musang:/etc/rc.d$

Here is the screenshot:

Slackware ls color meaning image

These are example of files (white), symbolic link (light blue@) and executable files (green*). For your information, those files above are 'daemons'. You'll play with them a lot soon. So remember the location. Type 'pwd' to check your current working directory and change your directory back to '/' by issue the command 'cd /'.

      
luzar@musang:/etc/rc.d$ pwd 
/etc/rc.d
luzar@musang:/etc/rc.d$ cd / 
luzar@musang:/$ ls 
bin/   dev/  home/  lost+found/  mnt/  proc/  sbin/  sys/  usr/
boot/  etc/  lib/   media/       opt/  root/  srv/   tmp/  var/ 
luzar@musang:/$

Let's view other directories to see what actually in there. Now, change directory into /usr directory. View the content with 'ls -l'.

      
luzar@musang:/$ cd /usr 
luzar@musang:/usr$ ls -l 
total 348
lrwxrwxrwx   1 root root      5 2008-09-06 08:32 X11 -> X11R6/
drwxr-xr-x   2 root root   4096 2008-09-06 08:32 X11R6/
drwxr-xr-x   2 root root   4096 2008-09-06 08:21 X11R6.bak/
lrwxrwxrwx   1 root root      8 2008-09-06 08:21 adm -> /var/adm/
drwxr-xr-x   2 root root  81920 2008-11-01 16:53 bin/
drwxr-xr-x   2 root root   4096 1993-11-26 11:40 dict/
drwxr-xr-x 570 root root  20480 2008-05-01 08:10 doc/
drwxr-xr-x   4 root root   4096 2007-06-24 14:57 i486-slackware-linux/
drwxr-xr-x 249 root root  49152 2008-09-20 23:03 include/
drwxr-xr-x   2 root root  12288 2007-02-22 05:58 info/
drwxr-xr-x 103 root root 135168 2008-11-01 16:53 lib/
drwxr-xr-x  15 root root   4096 2008-01-10 01:39 libexec/
drwxr-xr-x  11 root root   4096 1994-03-16 09:50 local/
drwxr-xr-x  45 root root   4096 2006-11-09 04:10 man/
drwxr-xr-x   2 root root  12288 2008-11-01 16:53 sbin/
drwxr-xr-x 158 root root   4096 2008-04-14 13:28 share/
lrwxrwxrwx   1 root root     10 2008-09-06 08:21 spool -> /var/spool/
drwxr-xr-x   4 root root   4096 2008-09-06 08:25 src/
lrwxrwxrwx   1 root root      8 2008-09-06 08:21 tmp -> /var/tmp/
luzar@musang:/usr$

In Slackware, this is the place where the Linux installation files are stored. You can type 'cd ..' to return to upper directory.

That's all for now.


The information provided

The information provided above is very useful for the linux beginner.I feel very interesting while reading the above article.If possible will you send me more details of above article?
Thanka & Regards,
shreekant c. tembhekar

Post new comment

The content of this field is kept private and will not be shown publicly.
This blog uses the CommentLuv Drupal plugin which will try and parse your sites feed and display a link to your last post, please be patient while it tries to find it for you.

Custom Search