Users coming from Windows background to Linux are often get confused about the file system of Linux. Linux “/” directory is often compared to Windows’ C: drive. But this is not correct. There are no drive letters in Linux. Let’s understand the Linux Filesystem Hierarchy Standard and the purpose of various directories present in it.
/bin – User Binaries
Bin means binary. This directory contains all kinds of executable files that are required in single user mode system. Many important commands like ls, ping etc. reside in this directory. At the same time, application programs such as Firefox etc. reside in the /usr/bin folder.
/sbin – System Binaries
Like /bin, /sbin also contains executable files. But it contains those binaries which are used by system administrators. Such as iptables, reboot, fdisk, ifconfig, swapon etc.
/boot – Boot Loader Files
The / boot directory contains files that are necessary for the computer to boot. The Linux kernel also resides in the / boot directory.
/dev – Device Files
In Linux all hardware devices appear as a file. All of your computer’s devices appear as files in the /dev directory. If enter the command ls /dev/disk/by-label then you will see all the partitions in your computer. Virtual devices are also present in this folder.
/etc – Application Configuration Files
You will find the configuration files of all the software you have installed in the /etc directory. If you are running LAMP server, then you will find the configuration files of php, apache and mysql in /etc folder.
/home – Home Folders
This is the home directory of all users of your Linux machine. Whenever a new user is created, a directory with the name of the user is created within the home directory, which contains other directories such as Desktop, Downloads, Documents, etc.
/lib – Essential Shared Libraries
The /lib folder contains the essential libraries which are used by /bin and /sbin binaries. The libraries for /usr/bin folder binaries reside in /usr/lib directory.
/media – Removable Media
In the /media folder, your files from removal storage devices such as folders and files of CDROM etc. are shown. For example, whenever you put a CD or DVD on your computer, a directory is created in the /media folder. And then you can access your CD / DVD files from there.
/mnt – Temporary Mount Points
This is the directory in which the system administrators mount the file systems. However, you can mount partitions in any folder.
/opt – Optional Packages
The /opt folder contains programs or packages that do not follow the standard file system hierarchy. For example, when installing a proprietary program, copy their files in the /opt/application folder.
/proc – Kernel & Process Files
Just as the /dev folder does not contain any actual files, instead hardware devices appear as files. Similarly there are no real files in /proc folder. /proc folder files represent system and process information.
/root – Root Home Directory
/root is the root user’s home directory. All other users have their home directory in /home/username while the root user’s home directory is in /root and not in /home/root.
/run – Application State Files
The /run folder contains temporary files of applications such as process IDs and sockets etc.
/selinux – SELinux Virtual File System
If your Linux distribution uses SELinux (eg. Fedora and Red Hat) for security, the /selinux directory contains special files used by SELinux. This is similar to the /proc folder.
/srv – Service Data
You can place files related to whatever services your system provides in the /srv folder. For example, if you use Apache server, you can place your website’s files in /srv folder.
/tmp – Temporary Files
Applications place their temporary files in the /tmp folder. Usually these files are cleared when the system restarts. But various applications keep deleting their files anytime.
/usr – User Binaries & Read-Only Data
The /usr folder contains files and binaries used by users. It mostly consists of multiuser utility and applications etc.
The /usr/bin directory contains binaries of non-essential applications and the non-essential system administration binaries are in the /usr/sbin folder. The libraries required for both of these directories reside in the /usr/lib directory.
Architecture independent files such as images etc. reside in the /usr/share directory. Where as locally compiled applications reside in the /usr/local directory.
/var – Variable Data Files
The /var directory contains files whose data changes continuously. Like log files, cache files etc. If you want to see php, mysql or any log files of your system, then you can find it on /var/log.