Updated on January 21st, 2021 – The Linux file system comes originally from UNIX and thus follows UNIX traditions. This is why for instance it uses the forward slash instead of the back slash as in Windows. Linux also differentiates between uppercase and lowercase letters, .e.g. the file with the name tesT is different than the file named TEst and so forth. Linux however, makes no difference between a directory and a file : “In UNIX everything is a file, if it is not, then it is a process” .
Unlike Windows users, Mac users might be more familiar with Linux since Mac has evolved from UNIX (was called BSD) .
You can see above a typical diagram of a Linux file system with all of the different folders or directories. As mentioned earlier, a directory is actually a file. You will notice this if you work with the command line.
Read: Differences between a thread and a process
If you issue the command :
ls – l
as displayed below :
You will see the type of the file shown at the beginning of the line. For example d stands for Linux directory and – for a normal file.
Here is a list of the common file types in Linux :
- – : regular file.
- d : directory.
- c : character device file.
- b : block device file.
- s : local socket file.
- p : named pipe.
- l : symbolic link.
To get a clear overview of what we’ll be covering, the following image breaks down the key areas of the Linux File System. It highlights five crucial aspects: File Types, Key Directories, System Configuration, User Data, and Service Data. We’ll explore each of these in detail throughout this guide.
Read: Understanding Linux File Permissions: The Complete Guide to Securing Your System Files
Read: The architecture of Linux operating system
1 – BIN
This folder will contain most if not all of the programs or applications of the machine. You will be able to find for instance the program dir which lists your directories and also the program echo which outputs text to the screen or to a file…
2 – BOOT
This is one of the important folders in Linux since it contains all the files the OS needs in order to boot,.i.e. This is where the boot loaders live, .e.g the file grub.conf which you find in the grub directory, the set of vmlinuz, initrd, system map and kernel related files …
The vmlinuz file (selected above) contains the current Linux kernel, which is loaded by grub before being executed. In other words, it the Linux kernel executable.
The System.map (shown above) file is used to debug crashes of the kernel. It has a list of kernel data or symbols along with the addresses these symbols are located at. Note that a symbol is just the building block of a given program: it can be a function name or a variable name. Each time the kernel compiles, a new System.map is file generated .
Read: How to speed up Linux
The initrd file (Linux initial RAM disk) : is a temporary file that contains different drivers and executables that are used to allow the root file system to be mounted. The kernel and the initrd are loaded to memory by the boot loader before starting the kernel.
The boot loader afterwards informs the kernel about the existence and whereabouts (where it is located in memory) of the initrd file. The kernel decompresses the initrd if it was compressed and mounts it as a temporary root file system. Another program called linuxrc is then started in order to carry out all the things necessary to mount the proper root file system.
The config file has a list of kernel configuration options which tell which features were compiled into the kernel and which were built as modules.
3 CDROM
It is just a legacy mounting point for your cd-rom that is left there for compatibility reasons. It is not found in all distros though.
4 DEV
DEV is the folder where all your devices live. You’ll find your hardware, .e.g your keyboard, your mouse, your printer…a disk for instance would be found as /dev/sda whereas and a partition on that disk would be for example /dev/sda1. This is a folder that applications and drivers will access.
Read: How to install and uninstall applications on Ubuntu
5 ETC
ETC directory in Linux, also called Etsy. It contains all configuration files (a configuration file a local file that controls the operation of a program) of the system or in its sub-directories.It is a good practice to backup this directory regularly as it will save a lot of re-configuration in case you re-install or lose your current installation.
6 HOME
Each user in Linux is assigned a specific directory that can only be accessed by them and the system administrator. This is where you store your personal files, install programs and save documents. The HOME directory in Linux contains also your personal configuration files also known as the dot files (a dot precedes the name of the file). These are usually ‘hidden’ and if you want to display them, you would have to switch on the appropriate option in your file manager or run the command ls with the -a switch in the terminal.
Read: Guide to Linux Config Files
For example, the dotfiles like .xsession and .bashrc, the configuration files for X and Bash respectively, live in this /home directory.
7 LIB and LIB 64
In the /lib directory we can find the kernel modules and also the shared library files that are needed by the boot operation of the system. Libraries can easily be identifiable via the extension of *.so. In Windows, the equivalent would be a dynamically linked library or DLL. Note that the Kernel modules ( including the drivers) are can be found in the subfolder /lib/modules/’kernel-version’.
8 MEDIA
MEDIA directory contains sub-directories in which removable media such as cdroms and USB keys can be mounted on by the system.
9 MNT
Contrary to the media folder mentioned previously, the MNT directory is the folder in which you ( or the system administrator ) mount devices or filesystems manually. The operation of making a filesystem available to the OS is called mounting. Note that some distros allocate /floppy and /cdrom (.e.g. Debian) as mount points whereas Redhat for instance put them in /mnt/floppy and /mnt/cdrom
10 OPT
OPT directory in linux is the optional folder where usually manually installed software and add-on packages from vendors reside (.i.e not part of the original installation).
Read: How to fix high memory usage in Linux
11 TEMP
TMP is a temporary directory where files are temporarily stored by applications . If you’re writing a document in LibreOffice for example, it will regularly save a temporary copy in this folder. It is usually emptied when you reboot the system. Sometimes you might find some files that have not been purged because the system can’t delete them. This is normally not a big deal unless there are hundreds of files in which case you might want to log in as the root user in single user mode and navigate to this folder in order to manually delete them.
12 USR
As one of the most important directories, /usr, contains all the user binaries along with their libraries, documentation etc.In other words, it is the “user usable programs and data” or User system resources as some people call it. Note that any application installed here is considered as non-essential for basic system operation.
13 VAR
‘/var’ contains variable data (like system logging files, printer spool directories, mail etc) that is expected to grow in size. For example:
– /var/crash holds information about processes that have crashed
– /var/mail Contains user mailbox files
– /var/log contains log files for both the system and other different applications.
– /var/lib contains dynamic data files/libraries.
– /var/spool spool data of applications
Read: Demystifying Linux Devices and Modules: A Practical Guide for Admins
14 SRV
This is the service directory where service data is stored. In case you run a server such as a web server or FTP server you would store the files that will be accessed by external users in /srv/ ( can be used for cfengine configs , svn repositories etc ..)
Conclusion
The Linux file system stands as a well-organized structure that forms the backbone of the entire operating system. Following its UNIX heritage, it employs a hierarchical directory structure where each component serves a specific purpose. From the essential boot files in /boot
that enable system startup, to the configuration files in /etc
that control system behavior, to the user data in /home
that stores personal information—each directory plays a vital role in maintaining system integrity and functionality.
This organization reflects Linux’s philosophy that “everything is a file,” which provides a consistent interface for managing resources. By understanding the purpose of key directories like /bin
, /dev
, /usr
, and /var
, users can navigate the system more effectively and gain deeper insight into how Linux operates. This knowledge is invaluable for system administrators, developers, and everyday users alike, as it empowers them to maintain, troubleshoot, and optimize their Linux systems with confidence.
Frequently Asked Questions (FAQ)
I. General Linux Filesystem Concepts:
- Q: How is the Linux filesystem different from the Windows filesystem in terms of slashes and case sensitivity?
- A: Linux uses forward slashes (
/
) to separate directories, while Windows uses backslashes (\
). Linux is also case-sensitive (meaningfile.txt
,File.txt
, andFILE.TXT
are all different files), whereas Windows is generally case-insensitive.
- A: Linux uses forward slashes (
- Q: What does the phrase “In UNIX everything is a file” mean in the context of the Linux filesystem?
- A: This means that almost everything in Linux, including directories, devices, and even processes, is represented as a file or can be interacted with as if it were a file. This provides a unified way of accessing and managing system resources.
- Q: How are Mac users potentially more familiar with the Linux filesystem than Windows users?
- A: macOS is derived from UNIX (specifically BSD), so its underlying filesystem structure and command-line interface share similarities with Linux.
- Q: What are the five crucial aspects of the Linux File System?
- A: File Types, Key Directories, System Configuration, User Data, and Service Data
II. Identifying File Types with ls -l
:
- Q: How can I see the type of a file or directory in Linux using the command line?
- A: Use the command
ls -l
(long listing). The first character of each line indicates the file type.
- A: Use the command
- Q: What does a hyphen (
-
) at the beginning of a line inls -l
output mean in Linux?- A: It indicates a regular file.
- Q: What does a
d
at the beginning of a line inls -l
output mean in Linux?- A: It indicates a directory.
- Q: What does a
c
at the beginning of a line inls -l
output represent in a Linux filesystem?- A: It represents a character device file (a device that handles data one character at a time, like a keyboard or serial port).
- Q: What does a
b
at the beginning of anls -l
listing signify on a Linux system?- A: It signifies a block device file (a device that handles data in blocks, like a hard drive or SSD).
- Q: In Linux
ls -l
output, what does ans
at the start of a line indicate?- A: It indicates a local socket file (used for inter-process communication).
- Q: How can I identify a named pipe in Linux using the
ls -l
command?- A: A named pipe will have a
p
at the beginning of the line in thels -l
output.
- A: A named pipe will have a
- Q: What does an
l
at the beginning of anls -l
line mean on a Linux or Unix system?- A: It means the file is a symbolic link (a shortcut or pointer to another file or directory).
III. Specific Directory Explanations (Long-Tail Keywords):
- Q: What is the purpose of the
/bin
directory in the Linux filesystem hierarchy?- A:
/bin
contains essential command binaries (executable programs) that are needed for basic system operation and are available to all users. Examples includels
,cp
,mv
,echo
, andcat
.
- A:
- Q: Where are the boot loader files, kernel, and
initrd
located in a standard Linux installation?- A: These files are located in the
/boot
directory.
- A: These files are located in the
- Q: What is the
vmlinuz
file in the/boot
directory, and what is its role in booting a Linux system?- A:
vmlinuz
is the compressed, executable Linux kernel itself. It’s loaded by the boot loader (like GRUB) and is the core of the operating system.
- A:
- Q: What is the purpose of the
System.map
file in the/boot
directory of a Linux system?- A:
System.map
is a symbol table used for debugging kernel crashes. It maps kernel symbols (function and variable names) to their memory addresses.
- A:
- Q: What is the
initrd
(initial RAM disk) file in/boot
, and how does it work during the Linux boot process?- A:
initrd
is a temporary filesystem loaded into memory during boot. It contains essential drivers and modules needed to mount the real root filesystem. This allows the system to boot even if the necessary drivers aren’t built directly into the kernel.
- A:
- Q: What information does the
config
file in the/boot
directory contain on a Linux system- A: The
config
file lists the kernel configuration options, indicating which features were compiled directly into the kernel and which were built as modules.
- A: The
- Q: Why is there a
/cdrom
directory in some Linux distributions, and is it still relevant?- A:
/cdrom
is a legacy mount point for CD-ROM drives. It’s often a symbolic link to a more appropriate location (like/media/cdrom
). It’s less relevant today as optical media usage has declined.
- A:
- Q: What kind of files are stored in the
/dev
directory on a Linux system?- A:
/dev
contains device files, which are special files that represent hardware devices (hard drives, partitions, keyboards, mice, etc.). Applications and drivers interact with hardware through these files.
- A:
- Q: What is the purpose of the
/etc
directory in the Linux filesystem, and why is it important to back it up?- A:
/etc
contains system-wide configuration files for the operating system and many applications. Backing it up is crucial because it stores settings that would be time-consuming to recreate if you had to reinstall the system.
- A:
- Q: Where are user home directories located in a standard Linux filesystem, and what do they contain?
- A: User home directories are located in
/home
. Each user has their own directory (e.g.,/home/username
) where they store personal files, application settings, and other data.
- A: User home directories are located in
- Q: What are “dot files” in a Linux user’s home directory, and how do I view them?
- A: Dot files are configuration files that are hidden by default. Their names start with a dot (e.g.,
.bashrc
). You can view them withls -a
(list all files) or by enabling “Show Hidden Files” in your file manager.
- A: Dot files are configuration files that are hidden by default. Their names start with a dot (e.g.,
- Q: Where are shared libraries (like
.so
files) located in the Linux filesystem, and what is their purpose?- A: Shared libraries are typically located in
/lib
and/lib64
(for 64-bit systems). They contain code that can be used by multiple programs, reducing redundancy and saving space..so
files are similar to DLLs in Windows.
- A: Shared libraries are typically located in
- Q: What is the difference between the
/media
and/mnt
directories in the Linux filesystem hierarchy?- A:
/media
is typically used for automatically mounting removable media (like USB drives and CDs)./mnt
is traditionally used for manually mounting filesystems or devices by the system administrator.
- A:
- Q: Where should I install optional, third-party software packages on a Linux system?
- A: The
/opt
directory is the recommended location for installing optional or add-on software packages that are not part of the core system distribution.
- A: The
- Q: What is the purpose of the
/tmp
directory in Linux, and is it safe to delete files from it?- A:
/tmp
stores temporary files created by applications. It’s generally safe to delete files from/tmp
, and the system usually clears it on reboot. However, deleting files that are actively in use by a running program can cause problems.
- A:
- Q: What is the
/usr
directory in Linux used for, and why is it considered one of the most important directories?- A:
/usr
contains user-installed applications, their libraries, documentation, and other data. It’s considered non-essential for basic system operation (the system can boot without it), but it’s essential for most user-level functionality.
- A:
- Q: What types of files are typically stored in the
/var
directory on a Linux system?- A:
/var
contains variable data files that are expected to change in size, such as log files (/var/log
), mail spools (/var/mail
), printer queues, and database files.
- A:
- Q: What is the purpose of the
/srv
directory in the Linux filesystem?- A:
/srv
is used to store data related to services provided by the system. For example, a web server might store its website files in/srv/www
or/srv/http
.
- A:
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.