Skip to main content

Command Palette

Search for a command to run...

Understanding the Linux File System: A Practical Guide for EC2 Ubuntu Instances

Published
5 min read
Understanding the Linux File System: A Practical Guide for EC2 Ubuntu Instances
M

Full-stack developer with a good foundation in frontend, now specializing in backend development. Passionate about building efficient, scalable systems and continuously sharpening my problem-solving skills. Always learning, always evolving.

If you've recently launched an EC2 instance on AWS using Ubuntu, you might have noticed a set of directories already present in your file system — such as /etc, /lib, /home, /root, /var, and many more. These directories aren't just random; they follow a well-established standard that governs how Linux operating systems are structured. Understanding these directories is essential if you're looking to manage, secure, and scale your server effectively.

In this blog, we'll explore each major directory, its purpose, and practical tips for managing and navigating them — especially in the context of AWS EC2 Ubuntu instances.


Why This Matters

Whether you're deploying a full-stack application, managing cloud infrastructure, or learning Linux, understanding the file system is foundational. When something goes wrong — a service won’t start, your disk space is low, or your app can't access a file — knowing where to look can save you hours of confusion.


Directory Breakdown (with Practical Tips)

1. / – Root Directory

This is the base of the entire Linux filesystem. Every other directory is a child of /.

Tip: Use cd / to return to the root directory from anywhere in the system.


2. /bin – Essential User Binaries

Contains essential commands and programs needed for system booting and repair. Commands like ls, cp, mv, and echo live here.

Example:

/bin/ls

Tip: Do not delete or modify files in /bin. These are crucial for normal system operation.


3. /boot – Boot Loader Files

Holds files necessary for booting the system, including the Linux kernel and GRUB bootloader.

Tip: Don’t modify unless you are performing kernel upgrades manually. Always back up first.


4. /dev – Device Files

A virtual directory representing system devices (e.g., hard drives, USBs).

Example: /dev/xvda1 is typically the main EC2 volume.

Tip: Never delete or alter files here. Use lsblk to safely inspect attached block devices.


5. /etc – Configuration Files

This is the control room of your system. It stores configuration files for the OS and installed software.

Examples:

  • /etc/ssh/sshd_config: Controls SSH access

  • /etc/nginx/nginx.conf: NGINX settings

Tip: Always back up a config file before editing:

sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

6. /home – User Home Directories

This is where non-root users store personal data. On EC2, you'll typically find /home/ubuntu.

Tip: Keep all your personal files, code, and scripts here. Avoid placing them in system directories.


7. /lib and /lib64 – Essential Shared Libraries

Contains shared library files needed by programs in /bin and /sbin.

Tip: Not typically user-managed. Avoid making changes unless you’re compiling software manually.


8. /media and /mnt – Mount Points

Used to mount external storage (USB drives, other volumes). On EC2, use /mnt for manually mounted EBS volumes.

Example:

sudo mkdir /mnt/data
sudo mount /dev/xvdf1 /mnt/data

Tip: Remember to unmount using umount before detaching the volume.


9. /opt – Optional Software

Stores manually installed software not managed by APT or other package managers.

Tip: Useful for custom software deployments. Example: placing a manually installed Node.js app in /opt/myapp.


10. /proc – Process and Kernel Info

A virtual filesystem showing real-time system data. Use it to inspect memory, CPU, or process details.

Examples:

  • /proc/cpuinfo

  • /proc/meminfo

Tip: This is read-only for most users. Do not attempt to write or delete anything here.


11. /root – Root User’s Home

Not to be confused with /, this is the home directory for the root user.

Tip: You can access it with sudo su and navigate to /root. Use caution — changes made as root can impact the system.


12. /run – Runtime Process Data

Contains temporary data used by services and processes at runtime.

Example:

ls /run/nginx.pid

Tip: Data here is cleared on reboot. Avoid storing important files.


13. /sbin – System Binaries

Holds commands for system administration like ifconfig, reboot, shutdown.

Tip: Used mostly by the root user. Use sudo when running commands from /sbin.


14. /srv – Service Data

A place to store service-specific data like web or FTP content.

Example: Place web files for a custom server in /srv/www/.


15. /sys – Kernel and Hardware Interface

Another virtual directory for interacting with kernel and hardware.

Tip: Mostly used for advanced debugging and hardware configuration. Avoid changes unless you know exactly what you're doing.


16. /tmp – Temporary Files

Programs use this for temporary data storage. Files here are deleted at reboot.

Tip: Never store important data here. Clean up regularly if you're running scripts or cron jobs that leave junk files.


17. /usr – User Applications and Utilities

Contains user-installed programs and shared resources.

  • /usr/bin: Non-essential user commands

  • /usr/lib: Libraries for these programs

Tip: Most of your installed software from apt resides here.


18. /var – Variable Files (Logs, Cache, DBs)

Used for files that change frequently like logs, mail, or databases.

Important Subdirectory:

  • /var/log — your primary destination when debugging issues.

Tip: To check for issues, run:

cd /var/log
less syslog
less auth.log

Final Thoughts

Navigating the Linux file system might seem overwhelming at first, but once you understand the role of each directory, it becomes a powerful tool for system management. Whether you're deploying applications, managing storage, or debugging issues — mastering this hierarchy will make you a much more effective engineer.

If you found this guide helpful, consider bookmarking it or sharing it with others who are just getting started with Linux on EC2.

Happy sysadmin-ing!


Written by Mohammad Aman + AI