Brief: This article gives a breakdown of the Linux File System/directory structure, some of the critical files, their usability, and their location.
You must have probably heard that everything is considered a file in UNIX and UNIX derivatives such as Linux. If not a file, then it must be a running process.
There are three broad categories of files in Linux.
- General Files – These are ordinary files made up of binary or ASCII data. These are regular files such as documents, images, audio and video files, etc.
- Directory Files – In Linux, directories are also categorized as files since they also serve as storage space for other files and folders.
- Device Files – These are special files that provide an interface to device drivers which enable the usability of hardware devices on the system such as mice, keyboards, USB devices, hard drives, etc. These are found in the /dev directory.
Linux Directory Structure Diagram
A standard Linux distribution follows the directory structure as provided below with Diagram and explanation.
Each of the above directories (which is a file, in the first place) contains important information, required for booting to device drivers, configuration files, etc. Describing briefly the purpose of each directory, we are starting hierarchically.
The root directory, denoted by a single forward slash
(/), is the uppermost directory in the Linux directory structure. It contains all directories, sub-directories, and files on your Linux system. It’s from the root directory where the Linux directory hierarchy starts.
NOTE: The root directory
(/) should not be confused with the root home directory
This is one of the most vital directories in a Linux system. As the name infers, the boot directory contains Linux boot files such as the bootloader, the kernel, and its associated files. Files such as ‘vmlinuz‘ represent the compressed image of the Linux kernel.
The /etc directory contains system configuration files for all the services, scripts, and third-party applications that are installed. This directory is considered the nerve center of the Linux system.
The /home directory is a directory that contains a user’s personal folders and files. On a graphical Linux system, the home directory, by default, contains folders such as Desktop, Documents, Downloads, Pictures, Videos, and Public.
In addition, the /home directory contains personal configuration files which are prefixed with a dot
(.). These are hidden files that contain user-specific settings for the login shell session.
The /root directory is the home directory for the root user, which is also referred to as the root user’s home directory (and not as the root
The root account also referred to as the superuser, administrative user, system administrator or just the root user has all the access to commands and system files in Linux.
The /opt directory is a directory that is reserved for add-on packages and third-party software applications that are not included by default in the system’s official repositories.
For example, when you install applications such as Skype, Discord, Spotify, and Java, to mention a few, they get stored in the /opt directory.
The /dev directory contains device files or special files for devices that are attached to the system such as the hard drive, keyboard, and mouse. As mentioned, these are not regular that a user can read and write to.
These are abstractions of standard devices that applications on your system interact with through input and output system calls.
The /var directory stores system-generated variable files, which include log files, caches, and spool files just to mention a few.
The /bin directory contains user binaries, executable programs, and common system commands that are used by all users in the system. These include ls, pwd, cat, mkdir, cd, mv, cp, du, df, tar, rpm, wc, history, etc.
The /sbin directory contains executable files, utilities, and system commands that are reserved for the root user or a user with root privileges. Such commands include halt, reboot, mkfs, fsck, fdisk, halt, iptables, ifconfig, ip, swapon, etc.
The /usr directory ranks as one of the most important directories due to the enormous amount of data it holds. The directory contains system-wide read-only files. These include libraries, user binaries and their documentation, programs, and system utilities.
The /proc directory is somewhat of a strange directory. It is a virtual or pseudo filesystem that contains vital information about running processes. It is considered the control and information center for the Linux kernel.
The filesystem is created on the fly upon system startup and is destroyed once the system is powered off.
The /mnt directory along with its subdirectories is a directory intended to be used as a temporary mount point for mounting storage devices such as Hard disk drives, USB drives, and CDROMs.
The /sys is a virtual file system that contains a set of virtual files that provide an interface to the Linux kernel.
The /media directory is a directory where the system mounts removable media such as USB drives.
The /run directory is a temporary filesystem that contains volatile runtime data that shows the system has since it was booted. Files under the /run directory must be deleted (removed or truncated as convenient) at the start of the boot process.
The /tmp directory is a directory that stores temporary files and many programs use this directory to create lock files and keep the temporary storage of data.
Do not delete files under the/tmp directory unless you know exactly what you are doing! Many of these files are critical for presently running programs and removing them may affect a system crash.
The /lib directory stores all the essential standard libraries required by user binaries in the /bin directory.
The lost+found directory is installed during the installation of Linux, useful for recovering files that may be broken due to unexpected shut-down.
The /srv directory is the service directory and is abbreviated as ‘srv‘. This directory contains server-specific and service-related files.
Exploring Important file, their location, and their Usability
Linux is a complex system that requires a more complex and efficient way to start, stop, maintain and reboot a system, unlike Windows. There is a well-defined configuration file, binaries, man pages, info files, etc. for every process in Linux.
In addition to the major directories, here is a list of some of the prominent files and directories and their uses.
- /boot/vmlinuz : The Linux Kernel file.
- /dev/hda : Device file for the first IDE HDD (Hard Disk Drive).
- /dev/hdc : Device file for the IDE Cdrom, commonly.
- /dev/sda: Device file for the first SATA Drive (Hard Disk Drive).
- /dev/null : A pseudo-device, that doesn’t exist. Sometimes garbage output is redirected to /dev/null, so that it gets lost, forever.
- /etc/bashrc : This file contains system-wide defaults, functions, and aliases among other files that are used by all the system users.
- /etc/crontab : This is a system-wide file that is uniquely formatted to schedule or automate system tasks on a Linux system.
- /etc/exports : A file that determines which file systems are exported to remote hosts and specifies options.
- /etc/fstab : This is a special file that contains information about all avaiable mount points and mount point options. Each line in this file provides six options, each of which denotes information about a mount point or filesystem.
- /etc/hosts : This is a configuration file that maps system hostnames to their corresponding IP addresses.
- /etc/hosts.allow : The file specifies which hosts are permitted to connect to the local system.
- /etc/host.deny : The file specifies which hosts are denied access and services on the local machine.
- /etc/issue : Contains a pre-login message.
- /etc/modules : This file contains the names of kernel modules that should be loaded at boot time, one per line.
- /etc/motd : motd stands for a message of the day, the message users get upon login.
- /etc/mtab : A read-only file that contains a list of currently mounted filesystems.
- /etc/passwd : A file that contains the system user’s information such as the username, UID, GID, and login shell among others
- /etc/printcap : Contains printer information that is generated by the /etc/cups/printers.conf file.
- /etc/profile : Contains Linux system-wide environment and other startup scripts.
- /etc/profile.d : Application script, executed after login.
- /etc/rc.d : Information about run level specific script.
- /etc/rc.d/init.d : Run Level Initialisation Script.
- /etc/resolv.conf : This is a DNS resolver file. It specifies how the system leverages DNS to resolve hostnames.
- /etc/security : Contains configuration files for various PAM modules.
- /etc/skel : This is a directory that contains a set of user configuration files that are copied to the user’s home directory when a user is created.
- /etc/X11 : This is a directory that contains configuration files for the X-window System.
- /usr/bin : Normal user executable commands.
- /usr/bin/X11 : This directory contains infinitely nested directories and binaries for the X Windows System.
- /usr/include : The directory contains header files for C compilers. This includes stdio.h, stdlib.h, and string.h among others.
- /usr/share : Shared directories of man files, info files, etc.
- /usr/lib : This directory consists of object files and directories
- /usr/sbin : The directory contains binaries with superuser privileges or for System Administration.
- /proc/cpuinfo : The file contains system info including CPU model, model name, number of cores, and clock speed to mention a few files.
- /proc/interrupts : Information about the current interrupts being utilized currently.
- /proc/ioports : The file contains all the Input/Output addresses used by devices on the server.
- /proc/meminfo : A file that stores memory usage information including swap information.
- /proc/modules : A file that lists all the modules being used by the kernel
- /proc/mount : The file contains detailed mounted file-system information.
- /proc/stat : The file contains detailed information about the system and kernel activity.
- /proc/swaps : The file contains information about the swap file.
- /proc/version : The file contains Linux version information.
- /var/log/lastlog : A binary file that contains information about the last successful user logins.
- /var/log/messages : The file contains a log of messages produced by the syslog daemon at boot.
- /var/log/syslog : A file that contains non-critical system logs.
- /var/log/wtmp : A file listing the login time and duration of each user on the system currently.
That’s all for now. Keep connected to Tecmint for any News and post related to Linux and Foss world. Stay healthy and Don’t forget to give your valuable comments in the comment section.
60 thoughts on “Linux Directory Structure and Important Files Paths Explained”
I am happy to say, that this site gives me some stuff to get Linux knowledge. We both are the same in searching for Linux. I think we could refer different sites to make us clear and more explanation may receive from that useful resources. I am not going to give up. I will be a best Linux user and reach admin level knowledge. all the best for all. contact me if you want to discuss it with me.
how can find the System Administration Guide like one provided from Red hat but not online with in the system, is it possible or no ?
Thanks friend for this wonderfull stuff, I love it although am new to linux
tryiny to get it all into my brain but I believe someday i’ll become a great linux
Please. Slow down. What’s a binary? What the difference between executable Windows and executable Linux, if any? What is Kernel, and is it comparable to Windows or Mac? What is source code? What are libraries? What are man pages? What is a shell? What is a shadow file? A bash shell? A terminal list? A swap file? Daemon?
what’s a binary? go to google, write: what’s a binary -> there you go. what is kernel? go to google, write: what is kernel -> there you go. what are libraries? go to google, write: what are libraries -> there you go, etc, etc, etc
Oh, since we are being sarcastic and non-helpful, you can just go to google, write: Linux filesystem -> there you go, and do away with the entire article.
Rather than being a smart yourself, perhaps you could have answered the many questions Anthony asked. The article is quite good but is not intended to be a complete and comprehensive be-all-end-all guide to the Linux OS.
Joydivision is right, the poster could do a little research himself rather than blasting the site with all those questions. It would have been just as easy to have typed those questions into a search engine and produced a usable answer.
I guess some people just need to, or are used to, having everything handed to them or are just too stupid or lazy to make use of the resources available, in which case they should probably continue to use Windows and leave Linux alone.
i have to install apache tomcat and jdk in linux server. So, can tell be where to install the software?
Also tell where to keep our developed application?
Well, IMHO (In My Humble Opinion,) going to a library, while not as instantly gratifying as a search engine, like Google, I feel that in the end, you will be FAR more knowledgeable about your chosen topic, that it’s a self-empowering choice. I cannot see a reason that would cause regret in choosing to obtain knowledge in this manner.
Can anyone share a higher quality picture of Linux Directory Structure above?
What’s above is termed the FHS (file hierarchy system) and that’s actually EXTREMELY detailed as it applies to ALL Linux systems, on any machine. If you use Kubuntu derived from Ubuntu derived from Debian, you’ll find the same EXACT file structure on all 3! Try that degree of uniformity over 3 versions of Windows or macOS. While they have an organized structure, it’s not defined that way!
Thanks for this little lesson.
How can install Apache web server, php and SQL on my Linux router which has built-in storage and SD card support?
Linux router? could you tell me the actual Linux distribution name? or you should follow our LAMP installation guides here: https://www.tecmint.com/tag/lamp
The Linux distribution is Busybox.
The Post is really amazing and very helpful, however need some guidance on understanding the difference in between /var/log/lastlog and /var/log/dmesg
The /var/log/lastlog file is used to keep succesful login information to the host, whereas /var/log/dmesg stores all Kernel ring buffers and system changes in real time.
Thanks for such valuable information