Linux

Linux Directory Structure and File system explained

The Linux  operating system has various distributions available like RHEL, Ubuntu, etc. are available in the community. But it is important to note that the filesystem and directory structure remains almost same. Even each and every file, folders in these distributions are considered as files only.

Overall there are three types of files in any Linux distributions as mentioned below:

  • General Files - As name suggests the files such as audio, video, documents, etc. which are consists of Binary or ASCII format.
  • Directory Files - The directories, sub directories created in Linux & Unix distributions fall into this category.
  • Device Files - When the devices like hard drive, USB, Mouse, etc. is connected to the system the directory (/dev) under which it gets mounted is called device files. Example: /dev/sd1, /dev/sd2 and so on.

The below diagram gives pictorial overview of various directories structure in Linux operating system.

Image: Linux Directory Structure

 

Linux Directories Explained

/ Directory 

  • The starting point of your directory structure. This is where the Linux system begins.
  • Every other file and directory on your system is under the root directory.
  • Usually the root directory contains only sub directories, so it's a bad idea to store single files directly under root.

/root - Root Superuser Directory

  • As name suggests this directory is home of root user. The initial directory created while spinning a new operating system.

/bin - User Binaries Directory

  • This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use.
  • /usr is the largest directory on a Linux system, and some people like to have it on a separate partition.

/boot - Boot Loader Files Directory

  • This is the place where Linux keeps information that it needs when booting up.
  • Contains kernel, grub files, etc

/dev - Device Files Directory

  • The devices that are available to a Linux system. In Linux, devices are treated like files and you can read and write devices like they were files.
  • For examples, /dev/fd0 is your first floppy drive, /dev/cdrom is your CD drive, /dev/hda is the first IDE hard drive, and so on.
  • All the devices that a Linux kernel can understand are located under /dev, and that's why it contains hundreds of entries.

/etc - Configuration Files Directory

  • The configuration files for the Linux system. Most of these files are text files and can be edited by hand.
  • For examples, /etc/fstab, /etc/passwd, /etc/inittab, etc

/home - Home Directory

  • This is where users keep their personal files. Every user has their own directory under /home, and usually it's the only place where normal users are allowed to write files.
  • You can configure a Linux system so that normal users can't even list the contents of other users' home directories.
  • For examples, /home /mark , /home/joe

/lib - Library (System and Shared) Directory

  • The shared libraries for programs that are dynamically linked.
  • The shared libraries are similar to DLL's on Windows.
  • Library filenames are either ld* or lib*.so.*

/media - Removable Media Devices Directory

  • The temporary mount directory for removable devices.
  • For example, /media/cdrom for CD-ROM, /media/cdrecorder for CD writer

/mnt - Mount Directory

  • This directory is used for temporary mount points.
  • The different physical storage devices (like the hard disk drives, floppies, CD-ROM's) must be attached to some directory in the file system tree before they can be accessed. This attaching is called mounting, and the directory where the device is attached is called the mount point.
  • The /mnt directory contains mount points for different devices, like /mnt/floppy for the floppy drive, /mnt/cdrom for the CD-ROM, and so on. However, you're not forced to use the /mnt directory for this purpose, you can use whatever directory you wish.
  • Actually in some distros, like Debian and SuSE, the default is to use /floppy and /cdrom as mount points instead of directories under /mnt.

/opt - Optional Addon Applications Directory

  • The /opt directory contains add-on applications from individual vendors.
  • Add-on applications should be installed under either /opt/ or /opt/ sub-directory.

/sbin - System Binaries Directory

  • Most system administration programs are stored in these directories.
  • In many cases you must run these programs as the root user.
  • For example, reboot, iptables

/srv - Service Data Directory

  • /srv contains site-specific data which is served by this system.
  • For example, /srv/physics/www, /srv/compsci/cvs

/tmp - Temporary Directory

  • The /tmp directory must be made available for programs that require temporary files.
  • Files under this directory are deleted when system is rebooted.

/usr - User Programs Directory

  • /usr is the second major section of the filesystem. /usr is shareable, read-only data.
  • That means that /usr should be shareable between various FHS-compliant hosts and must not be written to.
  • Any information that is host-specific or varies with time is stored elsewhere.
  • Large software packages must not use a direct subdirectory under the /usr hierarchy.

/var - Variable Files Directory

  • This directory contains variable data that changes constantly when the system is running.
  • For sample, /var/log, /var/spool, /var/mail

/proc - Process Information Directory

  • This is a special directory. Well, actually /proc is just a virtual directory, because it doesn't exist at all!
  • It contains some info about the kernel itself. There's a bunch of numbered entries that correspond to all processes running on the system, and there are also named entries that permit access to the current configuration of the system. Many of these entries can be viewed.
  • For example  /proc/pid

 

If any feedback, queries are always welcome!

Abhijit Sandhan

Love to Automate, Blog, Travel, Hike & spread Knowledge!

Related Articles

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button