https://www.geeksforgeeks.org/linux-file-hierarchy-structure/
The Linux File Hierarchy Structure or the Filesystem Hierarchy Standard (FHS) defines the directory structure and directory contents in Unix-like operating systems. It is maintained by the Linux Foundation.
- In the FHS, all files and directories appear under the root directory /, even if they are stored on different physical or virtual devices.
- Some of these directories only exist on a particular system if certain subsystems, such as the X Window System, are installed.
- Most of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS and are not considered authoritative for platforms other than Linux.
linux-directory
1. / (Root):
Primary hierarchy root and root directory of the entire file system hierarchy.
- Every single file and directory start from the root directory.
- The only root user has the right to write under this directory.
- /root is the root user’s home directory, which is not the same as /
root-linux-directory
2. /bin :
Essential command binaries that need to be available in single-user mode; for all users, e.g., cat, ls, cp.
- Contains binary executables.
- Common linux commands you need to use in single-user modes are located under this directory.
- Commands used by all the users of the system are located here e.g. ps, ls, ping, grep, cp
bin-linux-directory
3. /boot :
Boot loader files, e.g., kernels, initrd.
- Kernel initrd, vmlinux, grub files are located under /boot
- Example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic
boot-linux-directory
4. /dev :
Essential device files, e.g., /dev/null.
- These include terminal devices, usb, or any device attached to the system.
- Example: /dev/tty1, /dev/usbmon0
dev-linux-directory
5. /etc :
Host-specific system-wide configuration files.
- Contains configuration files required by all programs.
- This also contains startup and shutdown shell scripts used to start/stop individual programs.
- Example: /etc/resolv.conf, /etc/logrotate.conf.
etc-linux-directory
6. /home :
Users’ home directories, containing saved files, personal settings, etc.
Play
Unmute
- Home directories for all users to store their personal files.
- example: /home/kishlay, /home/kv
home-linux-directory
home-linux-directory
7. /lib:
Libraries essential for the binaries in /bin/ and /sbin/.
- Library filenames are either ld* or lib.so.
- Example: ld-2.11.1.so, libncurses.so.5.7
lib-linux-directory
8. /media:
Mount points for removable media such as CD-ROMs (appeared in FHS-2.3).
- Temporary mount directory for removable devices.
- Examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer
media-linux-directory
9. /mnt :
Temporarily mounted filesystems.
- Temporary mount directory where sysadmins can mount filesystems.
mnt-linux-directory
10. /opt :
Optional application software packages.
- Contains add-on applications from individual vendors.
- Add-on applications should be installed under either /opt/ or /opt/ sub-directory.
opt-linux-directory.
11. /sbin :
Essential system binaries, e.g., fsck, init, route.
- Just like /bin, /sbin also contains binary executables.
- The linux commands located under this directory are used typically by system administrators, for system maintenance purposes.
- Example: iptables, reboot, fdisk, ifconfig, swapon
sbin-linux-directory
12. /srv :
Site-specific data served by this system, such as data and scripts for web servers, data offered by FTP servers, and repositories for version control systems.
- srv stands for service.
- Contains server specific services related data.
- Example, /srv/cvs contains CVS related data.
srv-linux-directory
13. /tmp :
Temporary files. Often not preserved between system reboots and may be severely size restricted.
- Directory that contains temporary files created by system and users.
- Files under this directory are deleted when the system is rebooted.
tmp-linux-directory
14. /usr :
Secondary hierarchy for read-only user data; contains the majority of (multi-)user utilities and applications.
- Contains binaries, libraries, documentation, and source-code for second level programs.
- /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp
- /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
- /usr/lib contains libraries for /usr/bin and /usr/sbin
- /usr/local contains user’s programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2
- /usr/src holds the Linux kernel sources, header-files and documentation.
usr_bin-linux-directory
usr_sbin-linux-directory
usr_lib-linux-dirctory
usr_local-linux-directory
usr_src-linux-directory
15. /proc:
Virtual filesystem providing process and kernel information as files. In Linux, it corresponds to a procs mount. Generally, automatically generated and populated by the system, on the fly.
- Contains information about system process.
- This is a pseudo filesystem that contains information about running processes. For example: /proc/{pid} directory contains information about the process with that particular pid.
- This is a virtual filesystem with text information about system resources. For example: /proc/uptime
proc-linux-directory
proc-linux-directory
Modern Linux distributions include a /run directory as a temporary filesystem (tmpfs) which stores volatile runtime data, following the FHS version 3.0. According to the FHS version 2.3, such data were stored in /var/run but this was a problem in some cases because this directory is not always available at early boot. As a result, these programs have had to resort to trickery, such as using /dev/.udev, /dev/.mdadm, /dev/.systems or /dev/.mount directories, even though the device directory isn’t intended for such data.Among other advantages, this makes the system easier to use normally with the root filesystem mounted read-only. For example, below are the changes Debian made in its 2013 Wheezy release:
- /dev/.* ? /run/*
- /dev/shm ? /run/shm
- /dev/shm/* ? /run/*
- /etc/* (writable files) ? /run/*
- /lib/init/rw ? /run
- /var/lock ? /run/lock
- /var/run ? /run
- /tmp ? /run/tmp
?list=PLqM7alHXFySFc4KtwEZTANgmyJm3NqS_L See your article appearing on the GeeksforGeek’s main page and help other Geeks.
Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out – check it out now!
Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!
https://www.geeksforgeeks.org/linux-directory-structure/
In Linux/Unix operating system everything is a file even directories are files, files are files, and devices like mouse, keyboard, printer, etc are also files. Here we are going to see the Directory Structure in Linux.
Types of files in the Linux system.
- General Files – It is also called ordinary files. It may be an image, video, program, or simple text file. These types of files can be in ASCII or Binary format. It is the most commonly used file in the Linux system.
- Directory Files – These types of files are a warehouse for other file types. It may be a directory file within a directory (subdirectory).
- Device Files – In a Windows-like operating system, devices like CD-ROM, and hard drives are represented as drive letters like F: G: H whereas in the Linux system devices are represented as files. As for example, /dev/sda1, /dev/sda2, and so on.
We know that in a Windows-like operating system, files are stored in different folders on different data drives like C: D: E: whereas in the Linux/Unix operating system files are stored in a tree-like structure starting with the root directory as shown in the below diagram.
data storage in Linux/Unix operating systems
The Linux/Unix file system hierarchy base begins at the root and everything starts with the root directory.
These are the common top-level directories associated with the root directory:
Directories | Description |
---|---|
/bin | binary or executable programs. |
/etc | system configuration files. |
/home | home directory. It is the default current directory. |
/opt | optional or third-party software. |
/tmp | temporary space, typically cleared on reboot. |
/usr | User related programs. |
/var | log files. |
Some other directories in the Linux system:
Directories | Description |
---|---|
/boot | It contains all the boot-related information files and folders such as conf, grub, etc. |
/dev | It is the location of the device files such as dev/sda1, dev/sda2, etc. |
/lib | It contains kernel modules and a shared library. |
/lost+found | It is used to find recovered bits of corrupted files. |
/media | It contains subdirectories where removal media devices are inserted. |
/mnt | It contains temporary mount directories for mounting the file system. |
/proc | It is a virtual and pseudo-file system to contains info about the running processes with a specific process ID or PID. |
/run | It stores volatile runtime data. |
/sbin | binary executable programs for an administrator. |
/srv | It contains server-specific and server-related files. |
/sys | It is a virtual file system for modern Linux distributions to store and allows modification of the devices connected to the system. |
Exploring directories and their usability:
We know that Linux is a very complex system that requires an efficient way to start, stop, maintain and reboot a system, unlike Windows operating system. In the Linux system some well-defined configuration files, binaries, main pages information files are available for every process.
Linux Kernel File:
- /boot/vmlinux – The Linux kernel file.
Device Files:
- /dev/hda – Device file for the first IDE HDD.
- /dev/hdc – A pseudo-device that output garbage output is redirected to /dev/null.
System Configuration Files:
Configuration Files | Description |
---|---|
/etc/bashrc | It is used by bash shell that contains system defaults and aliases. |
/etc/crontab | A shell script to run specified commands on a predefined time interval. |
/etc/exports | It contains information on the file system available on the network. |
/etc/fstab | Information of the Disk Drive and their mount point. |
/etc/group | It is a text file to define Information of Security Group. |
/etc/grub.conf | It is the grub bootloader configuration file. |
/etc/init.d | Service startup Script. |
/etc/lilo.conf | It contains lilo bootloader configuration file. |
/etc/hosts | Information of IP and corresponding hostnames |
/etc/hosts.allow | It contains a list of hosts allowed accessing services on the local machine. |
/etc/host.deny | List of hosts denied accessing services on the local machine. |
/etc/inittab | INIT process and their interaction at the various run levels. |
/etc/issue | Allows editing the pre-login message. |
/etc/modules.conf | It contains the configuration files for the system modules. |
/etc/motd | It contains the message of the day. |
/etc/mtab | Currently mounted blocks information. |
/etc/passwd | It contains username, password of the system, users in a shadow file. |
/etc/printcap | It contains printer Information. |
/etc/profile | Bash shell defaults. |
/etc/profile.d | It contains other scripts like application scripts, executed after login. |
/etc/rc.d | It avoids script duplication. |
/etc/rc.d/init.d | Run Level Initialisation Script. |
/etc/resolv.conf | DNS being used by System. |
/etc/security | It contains the name of terminals where root login is possible. |
/etc/skel | Script that initiates new user home directory. |
/etc/termcap | An ASCII file that defines the behavior of different types of the terminal. |
/etc/X11 | Directory tree contains all the conf files for the X-window System. |
User Related Files:
User Related Files | Descriptions |
---|---|
/usr/bin | It contains most of the executable files. |
/usr/bin/X11 | Symbolic link of /usr/bin. |
/usr/include | It contains standard files used by C program. |
/usr/share | It contains architecture independent shareable text files. |
/usr/lib | It contains object files and libraries. |
/usr/sbin | It contains commands for Super User, for System Administration. |
Virtual and Pseudo Process Related Files:
Virtual and Pseudo Process Related Files | Descriptions |
---|---|
/proc/cpuinfo | CPU Information |
/proc/filesystems | It keeps useful info about the processes that are currently running. |
/proc/interrupts | it keeps the information about the number of interrupts per IRQ. |
/proc/ioports | Contains all the Input and Output addresses used by devices on the server |
/proc/meminfo | It reports the memory usage information. |
/proc/modules | Currently using kernel module. |
/proc/mount | Mounted File-system Information. |
/proc/stat | It displays the detailed statistics of the current system. |
/proc/swaps | It contains swap file information. |
Version Information File:
- /version – It displays the Linux version information.
Log Files:
Log Files | Descriptions |
---|---|
/var/log/lastlog | It stores user’s last login info. |
/var/log/messages | It has all the global system messages |
/var/log/wtmp | It keeps a history of login and logout information. |
To check the Linux directories, open the terminal and execute sudo -s followed by system password to give root privilege. Then after changing the current home directory to the root directory and check the list of all available directories in the base directory as shown below.
Linux directories
Conclusion
If we understand the Linux directory’s structure correctly, it would be so easy to effectively navigate and manage our filesystem, locate important configuration files, and access system information. One must know that the directory structure and specific file mentioned in this article are based on standard Linux conventions. We must consider that the different Linux distributions may have variations in the directory structure and specific file locations, but overall concept and organization remain similar.
Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out – check it out now!