{"id":153,"date":"2012-05-26T19:48:41","date_gmt":"2012-05-26T19:48:41","guid":{"rendered":"https:\/\/satyadeep.in\/blog\/?p=153"},"modified":"2012-08-07T10:24:45","modified_gmt":"2012-08-07T10:24:45","slug":"linux-file-system-directory-structure","status":"publish","type":"post","link":"https:\/\/satyadeep.in\/blog\/linux-file-system-directory-structure\/","title":{"rendered":"Linux File System (Directory Structure)"},"content":{"rendered":"<p>In this post I will be talking about how different external media or different partitions of a hard disk can be accessed in Linux and also about the various directories you\u2019ll find in\u00a0 a typical Linux Installation and the types of files each of these directories contain.<\/p>\n<p>The first thing you\u2019ll need to know is that the entire file system in Linux comprises of a single main directory called the root(\/) directory and every other directory is a sub-directory of the root directory. Linux does not represent different partitions as different drive letters as in Windows. The partitions are\u00a0 \u201cmounted\u201d as different sub-directories under the root file system. The default mounting directory is the \/mnt or the \/media directory in most Linux distributions. The partitions can also be mounted to other directories under the root\u00a0 other than the \/mnt or \/media directories, by manual configuration.<\/p>\n<p>Don\u2019t worry if you did not understand what \u201cmounting\u201d means. For now it suffices to understand that \u201cmounting a partition to a folder\u201d means simply to make the contents of the partition accessible by showing them in a specified folder.<\/p>\n<p>So different partitions on the same hard disk or\u00a0 various devices like USB sticks, External Hard Disks and CDs would be mounted to normal directories under the root directory, from where their files can be accessed or manipulated.<\/p>\n<p>For example by mounting a CD to a subdirectory like \/home\/User1\/Desktop\/CD all the contents of the CD can be accessed through that directory.<\/p>\n<p>So how does this system of mounting partitions and external media as sub-directories under the root directory make any sense?<\/p>\n<p>Isn\u2019t the Windows\u2019 way of showing them as different devices and drives simple and easy? All the immovable files like the system files , installed program files , user home folders are all on the Windows\u2019\u00a0 partition (usually the C:\\ drive) and all the other data which can be moved around without any problems, in the other partitions.<\/p>\n<p>Simple and sweet right? Well it does seem simple but does that make the system flexible? Well not quite. Let\u2019s see why.<\/p>\n<p>Windows is very rigid with regards to the location of its files and the installed programs.They have to be on the same partition and the names and locations of the directories cannot be changed\u00a0 without running into problems and the risk of system instability.<\/p>\n<p>On a Windows system can you even fathom the thought of\u00a0 having the \u201cProgram Files\u201d folder on one hard disk, the Windows folder on another partition on a different hard disk while having the system32 folder on a network file system. It seems impossible doesn\u2019t it? Well it is, on a Windows system. But not on Linux.<\/p>\n<p>The mounting process\u00a0 in Linux applies not only to external drives and other storage media but even to the system partitions that are essential to the running of Linux. They can be mounted from a different partition or from a different hard disk or even from a remote location on the network altogether.<\/p>\n<p>Since partitions can be mounted as sub-directories, we can mount the directories required for the running of the system, from different partitions on the same hard disk or from different devices, or even from a network location, provided that all the partitions are mounted to the correct locations. The underlying kernel will not see the difference, since everything will seem like a single file system and it is oblivious to the fact that the different folders have been fetched from different locations.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/satyadeep.in\/blog\/wp-content\/uploads\/2012\/05\/FileSystemMountingLinux.png\"><img decoding=\"async\" style=\"width: 772px; display: inline; border-width: 0px;\" title=\"FileSystemMountingLinux\" src=\"https:\/\/satyadeep.in\/blog\/wp-content\/uploads\/2012\/05\/FileSystemMountingLinux_thumb.png\" alt=\"FileSystemMountingLinux\" width=\"685\" height=\"413\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>So that\u2019s the kind of advantage the Linux\u2019s system of mounting file systems, has.Makes more sense now right?<\/p>\n<p>Ok, enough about mounting.Wondering what \u201c\/usr\u201d,\u201d\/etc\u201d,\u201d\/home\u201d in the above picture mean? We are going right to that topic now.<\/p>\n<p>Let\u2019s see what the different sub-directories of the root directory are and what types of files they contain.<\/p>\n<p>Note: We will talk about the commands required to mount a device or partition in a different post.<\/p>\n<p>The root directory is denoted by the forward slash \u201c\/\u201d. The different sub directories under the root directory are as follows:<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/satyadeep.in\/blog\/wp-content\/uploads\/2012\/05\/Directories.png\"><img decoding=\"async\" style=\"width: 682px; display: inline; border-width: 0px;\" title=\"Directories\" src=\"https:\/\/satyadeep.in\/blog\/wp-content\/uploads\/2012\/05\/Directories_thumb.png\" alt=\"Directories\" width=\"682\" height=\"824\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the contents of the directories can be seen in the following tree structure<\/p>\n<p>\/<br \/>\n|\u2014<strong>bin<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The <strong>bin<\/strong> folder contains binaries(Executable files) that are used by the system as well as the users<br \/>\n|\u00a0\u00a0 |\u2014bash<br \/>\n|\u00a0\u00a0 |&#8211; cat<br \/>\n|\u00a0\u00a0 |&#8211; chgrp<br \/>\n|\u00a0\u00a0 |&#8211; chmod<br \/>\n|\u00a0\u00a0 |&#8211; chown<br \/>\n|\u00a0\u00a0 |&#8211; cp<br \/>\n|\u00a0\u00a0 |&#8211; date<br \/>\n|\u00a0\u00a0 |&#8211; dd<br \/>\n|\u00a0\u00a0 |&#8211; df<br \/>\n|\u00a0\u00a0 |&#8211; dir<br \/>\n|\u00a0\u00a0 |&#8211; dmesg<br \/>\n|\u00a0\u00a0 |&#8211; grep<br \/>\n|\u00a0\u00a0 |&#8211; gzip<br \/>\n|\u00a0\u00a0 |&#8211; hostname<br \/>\n|\u00a0\u00a0 |&#8211; ip<br \/>\n|\u00a0\u00a0 |&#8211; kill<br \/>\n|\u00a0\u00a0 |&#8211; less<br \/>\n|\u00a0\u00a0 |&#8211; ln<br \/>\n|\u00a0\u00a0 |&#8211; login<br \/>\n|\u00a0\u00a0 |&#8211; ls<br \/>\n|\u00a0\u00a0 |&#8211; mkdir<br \/>\n|\u00a0\u00a0 |&#8211; more<br \/>\n|\u00a0\u00a0 |&#8211; mount<br \/>\n|\u00a0\u00a0 |&#8211; mv<br \/>\n|\u00a0\u00a0 |&#8211; ping<br \/>\n|\u00a0\u00a0 |&#8211; ps<br \/>\n|\u00a0\u00a0 |&#8211; pwd<br \/>\n|\u00a0\u00a0 |&#8211; rm<br \/>\n|\u00a0\u00a0 |&#8211; su<br \/>\n|\u00a0\u00a0 |&#8211; sync<br \/>\n|\u00a0\u00a0 |&#8211; tar<br \/>\n|\u00a0\u00a0 |&#8211; touch<br \/>\n|\u00a0\u00a0 |&#8211; uname<br \/>\n|\u00a0\u00a0 |&#8211; uncompress<br \/>\n|\u00a0\u00a0 `&#8211; which<br \/>\n|\u2014<strong>boot\u00a0 <\/strong>\u00a0 (The <strong>boot<\/strong> folder contains the bootstrap loader like LILO or GRUB and the Linux Kernel)<br \/>\n|\u00a0\u00a0 |&#8211; grub<br \/>\n|\u00a0\u00a0 |&#8211; initrd.img-2.6.31-20-generic<br \/>\n|\u00a0\u00a0 `&#8211; vmlinuz-2.6.31-20-generic\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (This is the Linux Kernel)<br \/>\n|\u2014<strong>dev\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong>(The <strong>dev <\/strong>folder contains files representing the various hardware on the system and as well as<br \/>\n|\u00a0\u00a0 |\u2014disk\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the different virtual consoles)<br \/>\n|\u00a0\u00a0 |&#8211; loop0<br \/>\n|\u00a0\u00a0 |&#8211; loop1<br \/>\n|\u00a0\u00a0 |&#8211; loop2<br \/>\n|\u00a0\u00a0 |&#8211; port<br \/>\n|\u00a0\u00a0 |&#8211; ppp<br \/>\n|\u00a0\u00a0 |&#8211; psaux<br \/>\n|\u00a0\u00a0 |&#8211; ram0<br \/>\n|\u00a0\u00a0 |&#8211; ram1<br \/>\n|\u00a0\u00a0 |&#8211; sda<br \/>\n|\u00a0\u00a0 |&#8211; sda1<br \/>\n|\u00a0\u00a0 |&#8211; tty<br \/>\n|\u00a0\u00a0 |&#8211; tty0<br \/>\n|\u00a0\u00a0 |&#8211; tty1<br \/>\n|\u00a0\u00a0 |&#8211; ttyS0<br \/>\n|\u00a0\u00a0 `&#8211; usbmon0<br \/>\n|<br \/>\n|\u2014<strong>etc<\/strong><br \/>\n|\u00a0\u00a0 |&#8211; X11<br \/>\n|\u00a0\u00a0 |&#8211; apache2<br \/>\n|\u00a0\u00a0 |&#8211; apt<br \/>\n|\u00a0\u00a0 |&#8211; cron.d<br \/>\n|\u00a0\u00a0 |&#8211; grub.d<br \/>\n|\u00a0\u00a0 |&#8211; hostname<br \/>\n|\u00a0\u00a0 |&#8211; hosts<br \/>\n|\u00a0\u00a0 |&#8211; inetd.conf<br \/>\n|\u00a0\u00a0 |&#8211; init<br \/>\n|\u00a0\u00a0 |&#8211; init.d<br \/>\n|\u00a0\u00a0 |&#8211; rc0.d<br \/>\n|\u00a0\u00a0 |&#8211; rc1.d<br \/>\n|\u00a0\u00a0 |&#8211; skel<br \/>\n|\u00a0\u00a0 |&#8211; sound<br \/>\n|\u00a0\u00a0 `&#8211; sysctl.conf<br \/>\n|&#8211; <strong>home<\/strong><br \/>\n|\u00a0\u00a0 `&#8211; User1<br \/>\n|<br \/>\n|&#8211; <strong>lib<br \/>\n<\/strong>|\u00a0\u00a0 |&#8211; lsb<br \/>\n|\u00a0\u00a0 |&#8211; modules<br \/>\n|\u00a0\u00a0 |&#8211; security<br \/>\n|\u00a0\u00a0 `&#8211; terminfo<br \/>\n|<br \/>\n|&#8211; <strong>lib32<\/strong><br \/>\n|\u00a0\u00a0 |&#8211; i486<br \/>\n|\u00a0\u00a0 `&#8211; i586<br \/>\n|<br \/>\n|&#8211;<strong> lib64<\/strong><br \/>\n|&#8211; <strong>lost+found<\/strong><br \/>\n|&#8211; <strong>media<br \/>\n<\/strong>|\u00a0\u00a0 |&#8211; New Volume<br \/>\n|\u00a0\u00a0 `&#8211; cdrom<br \/>\n|<br \/>\n|&#8211; <strong>mnt<br \/>\n<\/strong>|&#8211; <strong>opt<br \/>\n<\/strong>|\u00a0\u00a0 |&#8211; cxoffice<br \/>\n|\u00a0\u00a0 |&#8211; google<br \/>\n|\u00a0\u00a0 `&#8211; openoffice.org<br \/>\n|<br \/>\n|&#8211; <strong>proc<\/strong><br \/>\n|\u00a0\u00a0 |&#8211; 1<br \/>\n|\u00a0\u00a0 |&#8211; 17052<br \/>\n|\u00a0\u00a0 |&#8211; 2685<br \/>\n|\u00a0\u00a0 |&#8211; 28<br \/>\n|\u00a0\u00a0 |&#8211; 5<br \/>\n|\u00a0\u00a0 |&#8211; 70<br \/>\n|\u00a0\u00a0 |&#8211; 9<br \/>\n|\u00a0\u00a0 |&#8211; acpi<br \/>\n|\u00a0\u00a0 |&#8211; cpuinfo<br \/>\n|\u00a0\u00a0 |&#8211; devices<br \/>\n|\u00a0\u00a0 |&#8211; driver<br \/>\n|\u00a0\u00a0 `&#8211; fs<br \/>\n|<br \/>\n|&#8211; <strong>root<br \/>\n<\/strong>|&#8211; <strong>sbin<br \/>\n<\/strong>|\u00a0\u00a0 |&#8211; alsa<br \/>\n|\u00a0\u00a0 |&#8211; dumpe2fs<br \/>\n|\u00a0\u00a0 |&#8211; fdisk<br \/>\n|\u00a0\u00a0 |&#8211; halt -&gt; reboot<br \/>\n|\u00a0\u00a0 |&#8211; ifconfig<br \/>\n|\u00a0\u00a0 |&#8211; ifdown<br \/>\n|\u00a0\u00a0 |&#8211; ifup<br \/>\n|\u00a0\u00a0 |&#8211; init<br \/>\n|\u00a0\u00a0 |&#8211; iwconfig<br \/>\n|\u00a0\u00a0 |&#8211; iwevent<br \/>\n|\u00a0\u00a0 |&#8211; mke2fs<br \/>\n|\u00a0\u00a0 |&#8211; mkfs<br \/>\n|\u00a0\u00a0 |&#8211; partprobe<br \/>\n|\u00a0\u00a0 `&#8211; reboot<br \/>\n|<br \/>\n|&#8211; <strong>sys<br \/>\n<\/strong>|\u00a0\u00a0 |&#8211; block<br \/>\n|\u00a0\u00a0 |&#8211; bus<br \/>\n|\u00a0\u00a0 |&#8211; kernel<br \/>\n|\u00a0\u00a0 |&#8211; module<br \/>\n|\u00a0\u00a0 `&#8211; power<br \/>\n|&#8211; <strong>tmp<\/strong><br \/>\n|<br \/>\n|&#8211; <strong>usr<br \/>\n<\/strong>|\u00a0\u00a0 |&#8211; bin<br \/>\n|\u00a0\u00a0 |&#8211; games<br \/>\n|\u00a0\u00a0 |&#8211; include<br \/>\n|\u00a0\u00a0 |&#8211; lib<br \/>\n|\u00a0\u00a0 |&#8211; local<br \/>\n|\u00a0\u00a0 |&#8211; man<br \/>\n|\u00a0\u00a0 |&#8211; info<br \/>\n|\u00a0\u00a0 |&#8211; sbin<br \/>\n|\u00a0\u00a0 |&#8211; share<br \/>\n|\u00a0\u00a0 `&#8211; src<br \/>\n|&#8211; <strong>var<br \/>\n<\/strong>\u00a0\u00a0\u00a0 |&#8211; backups<br \/>\n|&#8211; cache<br \/>\n|&#8211; log<br \/>\n|&#8211; mail<br \/>\n|&#8211; spool<br \/>\n|&#8211; tmp<br \/>\n`\u2014www<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>As you can see above, the<\/p>\n<p>&nbsp;<\/p>\n<p>The \/usr\/sbin directory contains non-vital system utilities that are used after booting (i.e., starting the system) by the system administrator.<\/p>\n<p>This is in contrast to the \/sbin directory, whose contents include vital system utilities that are necessary before the \/usr directory has been mounted (i.e., attached logically to the main filesystem).<\/p>\n<p>\/bin is a standard subdirectory of the root directory in Unix-like operating systems that contains the executable (i.e., ready to run) programs that must be available in order to attain minimal functionality for the purposes of booting (i.e., starting) and repairing a system.<\/p>\n<p>&nbsp;<\/p>\n<p>\/bin \/sbin \u2013 required for booting\u00a0\u00a0\u00a0 \/usr\/sbin \u2013not reuired for booting<\/p>\n<p>The \/sbin and \/usr\/sbin directories are in the path (The standard location where the operating system searches for binaries to run commands) of the root user only but not for ordinary users since they are not meant for normal users without privileges.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/dev<\/p>\n<p>. Look through this directory and you should see hda1, hda2 etc,<br \/>\nwhich represent the various partitions on the first master drive of the<br \/>\nsystem. \/dev\/cdrom and \/dev\/fd0 represent your CDROM drive and your floppy<br \/>\ndrive. This may seem strange but it will make sense if you compare the<br \/>\ncharacteristics of files to that of your hardware. Both can be read from<br \/>\nand written to. Take \/dev\/dsp, for instance. This file represents your<br \/>\nspeaker device. So any data written to this file will be re-directed to<br \/>\nyour speaker. Try &#8216;cat \/etc\/lilo.conf &gt; \/dev\/dsp&#8217; and you should hear some<br \/>\nsound on the speaker. That&#8217;s the sound of your lilo.conf file! Similarly,<br \/>\nsending data to and reading from \/dev\/ttyS0 ( COM 1 ) will allow you to<br \/>\ncommunicate with a device attached there &#8211; your modem.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/etc<\/p>\n<p>\/etc &#8211; This directory contains all the configuration files for your system.<br \/>\nYour lilo.conf file lies in this directory as does hosts, resolv.conf and<br \/>\nfstab. Under this directory will be X11 sub-directory which contains the<br \/>\nconfiguration files for X. More importantly, the \/etc\/rc.d directory<br \/>\ncontains the system startup scripts. This is a good directory to backup<br \/>\noften. It will definitely save you a lot of re-configuration later if you<br \/>\nre-install or lose your current installation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will be talking about how different  [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[11],"tags":[17,4],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-linux-2","tag-file-system","tag-linux"],"_links":{"self":[{"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":3,"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/posts\/153\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/satyadeep.in\/blog\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}