DEV Community

Samkeliso Dube
Samkeliso Dube

Posted on

Getting to Know the Linux Filesystem as a DevOps Beginner

While working on my EC2 instance, I kept coming across paths like /etc, /var/log, and /usr/share. I wanted to understand what these directories do and when I might need them while managing a Linux server.

To make things easier to understand, I started thinking of the Linux filesystem as a house.

Imagine / (the root directory) as the entire house. Inside the house, there are different rooms, each with its own purpose. You wouldn't keep everything in one room, right?

Linux works in a similar way. It organizes files into directories, and each directory has a particular purpose.

Let's explore the directories I found on my EC2 instance and learn what they do.

Linux File System

Linux Filesystem Hierarchy

1. / The Root Directory

Let's start with /, the root directory.

Remember our house analogy? If Linux were a house, / would represent the entire house. All the other directories, such as /home, /etc, /var, and /usr, are located under it.

In Linux, / is the starting point of the filesystem hierarchy. Every file and directory has a place within this structure, even when files are stored on different disks or filesystems.

2. /bin Essential Commands

Think of /bin as a cupboard in our house where we keep the basic tools we use every day.

In Linux, /bin contains essential commands that help us perform everyday tasks, such as listing files, copying files, and displaying file contents.

For example:

  • ls lists files and directories.
  • cp copies files and directories.
  • cat displays the contents of a file.

3. /boot Boot Files

Think of /boot as the part of our house that holds what we need to get the house up and running.

In Linux, /boot contains files needed to start the operating system. These may include the Linux kernel and files used by the bootloader, which helps the computer load Linux when it starts.

When you switch on a computer, it needs to load the operating system before you can start using it. The files in /boot help make that process possible.

4. /dev Device Files

Think of /dev as the place in our house where we find things like the lights, taps, and other equipment we use.

In Linux, /dev contains special files that provide a way for the operating system and applications to interact with devices and certain system resources.

For example:

  • /dev/sda may represent a disk device.
  • /dev/null discards anything sent to it.
  • /dev/tty represents the terminal associated with a process.

These are not ordinary files like a document or a picture. They provide interfaces for working with devices or system resources.

5. /etc Configuration Files

Think of /etc as the place in our house where we keep the instructions for how things should work.

In Linux, /etc` contains configuration files that control how the system and its applications behave.

For example:

  • /etc/ssh/sshd_config contains settings for the SSH server.
  • /etc/hostname contains the system's hostname.

6. /home Users' Personal Directories

Think of /home as the bedrooms in our house, where each person keeps their personal belongings.

In Linux, /home contains personal directories for regular users. Each user can store their own files, documents, and projects there.

For example, if a user named sam has an account on the system, their personal directory might be /home/sam.

7. /lib Essential Libraries

Think of /lib as a cupboard where we keep the small parts that help our tools work.

In Linux, /lib contains essential libraries that programs and commands need to run. A library is a collection of ready-made code that a program can use instead of having to do everything from scratch.

For example, a program may need a library to perform certain operations. Without the required library, the program might fail to run.

8. /media Removable Devices

Think of /media as the place near the entrance of our house where we connect things we bring from outside, like a USB stick.

In Linux, /media is commonly used as a place to access removable devices, such as USB drives, when they are connected to the computer.

For example, when you plug a USB drive into a Linux computer, the system may make its files accessible through a directory under /media.

9. /mnt Temporary Mount Point

Think of /mnt as a temporary place in our house where we put something when we need to use it for a while.

In Linux, /mnt is commonly used as a place to temporarily attach another filesystem so that its files can be accessed.

For example, a system administrator might mount an additional disk at /mnt to access its files.

10. /opt Optional Software

Think of /opt as a separate room in our house where we keep additional things we choose to bring in.

In Linux, /opt is commonly used to store additional software, especially applications that are installed separately from the software normally provided by the system.

For example, a third-party application might place its files inside /opt.

11. /proc Process and System Information

Think of /proc as a noticeboard in our house that shows us what is happening inside.

In Linux, /proc provides information about running processes and the system itself. The files you see here are virtual files, meaning they are generated by the kernel rather than stored as ordinary files on a disk.

For example:

  • /proc/cpuinfo shows information about the CPU.
  • /proc/meminfo shows information about memory.
  • /proc/1/ contains information about the process with process ID 1.

12. /root The Root User's Home Directory

Think of /root as the private bedroom of the person in charge of our house.

In Linux, /root is the home directory of the root user, which is the system's administrator account. It is where the root user can store personal files and other items.

One important thing to remember is that /root and / are different:

/ is the starting point of the entire Linux filesystem.

/root is the home directory belonging to the root user.

13. /run Runtime Information

Think of /run as a noticeboard in our house where we keep information about what is happening right now.

In Linux, /run stores temporary system information created since the system started. This information helps programs and services keep track of their current activities.

For example, Linux may store information about running services, process IDs, and communication sockets here.

Unlike /var, which can hold data that remains between reboots, the contents of /run are temporary and are generally cleared when the system restarts.

14. /sbin System Administration Commands

Think of /sbin as a cupboard where we keep tools used to maintain and repair our house.

In Linux, /sbin traditionally contains commands used for system administration, such as managing disks, checking filesystems, and maintaining the system.

For example:

  • fsck checks and can repair filesystems.
  • reboot restarts the system.

On many modern Linux systems, /sbin is a symbolic link to /usr/sbin.

15. /srv Data for Services

Think of /srv as a room in our house where we keep things that we provide to visitors.

In Linux, /srv is intended to hold data served by services running on the system. For example, a server might store files here that it makes available to users over a network.

The exact contents depend on how the system is configured. Not every Linux server uses /srv.

16. /sys System and Device Information

Think of /sys as a noticeboard in our house that tells us about the equipment we have and how it is connected.

In Linux, /sys provides information about devices, drivers, and parts of the kernel. Like /proc, it contains virtual files rather than ordinary files stored on disk.

For example, Linux can use /sys to expose information about storage devices and network interfaces.

17. /tmp Temporary Files

Think of /tmp as a table in our house where we put things we need for a short time.

In Linux, /tmp is used to store temporary files created by programs and users while they work.

For example, an application might create a temporary file while processing information and no longer need it afterward.

Files in /tmp may be deleted automatically, including during a system reboot, depending on how the system is configured. Therefore, it is not a good place to keep important files permanently.

18. /usr Programs and Shared Resources

Think of /usr as a part of our house where we keep many of the tools and resources we use.

In Linux, /usr contains many programs, libraries, and shared files used by the system and its applications.

For example:

  • /usr/bin contains many commands and programs.
  • /usr/lib contains libraries used by programs.
  • /usr/share contains shared files, such as documentation and other resources.

When I explored my Amazon Linux EC2 instance, I also came across /usr/share/nginx/html/ in the Nginx logs. On my instance, this was the directory Nginx was trying to access for website files.

The web root can vary depending on the Nginx configuration. For example, some Ubuntu setups commonly use /var/www/html/.

19. /var Variable Data

Think of /var as a storage room in our house where we keep things that change or grow over time.

In Linux, /var contains data that programs and services create or update while the system is running.

For example:

  • /var/log stores log files that help us understand what is happening on the system.
  • /var/lib stores data that applications and services need to keep.
  • /var/cache stores temporary data that can be reused to make things faster.
  • /var/tmp stores temporary files that may need to remain available longer than files in /tmp.

Why Understanding the Linux Filesystem Matters in DevOps

As I continue learning Linux and working with cloud servers, understanding the filesystem helps me know where to look when I need to investigate an issue.

For example, if I need to check configuration settings, I know to start with /etc. If I want to investigate logs, /var/log is a useful place to look. If I need to understand how a program or service is running, directories such as /proc can provide helpful information.

I'm learning that working with Linux isn't just about memorizing commands. It's also about understanding how the system is organized and knowing where to look when something goes wrong.

I'm still learning, and exploring these directories on my EC2 instance has helped me connect Linux concepts with practical experience.

One step at a time, one directory at a time.

linux #devops #beginners #aws

Top comments (0)