Directory Structure

Linux follows a standardized directory hierarchy called the Filesystem Hierarchy Standard (FHS). This means once you learn the structure, you'll feel at home on any Linux system.

The Root Directory

Everything in Linux starts from the root directory, represented by a single forward slash (/). Unlike Windows with separate drives (C:, D:), Linux has one unified filesystem tree.

Visualize It: Think of the root directory as the trunk of a tree. All other directories are branches that grow from this trunk.

Essential Directories

Let's explore the most important directories you'll encounter as a web developer:

/ (Root)

The top-level directory. All other directories are contained within root.

user@ubuntu:~$ ls /
bin   boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

/bin - Essential User Binaries

Contains essential command-line programs needed by all users. These are the basic commands you'll use every day.

user@ubuntu:~$ ls /bin | head -10
[   bash   cat   chmod   cp   date   dd   df   echo   false
Key Commands: ls, cp, mv, rm, cat, echo - these are your daily tools.

/home - User Home Directories

Where users store their personal files. Each user gets their own subdirectory.

user@ubuntu:~$ ls /home
user1  user2  valente

user@ubuntu:~$ pwd
/home/valente
Web Development: Your web projects will typically live in your home directory, often in a folder like ~/projects/ or ~/www/.

/etc - System Configuration

Contains all system-wide configuration files. This is where you'll find settings for web servers, databases, and other services.

user@ubuntu:~$ ls /etc | grep "nginx\|apache\|mysql"
nginx  mysql  apache2
Important: You'll need sudo (administrator privileges) to modify files in /etc. Be careful - a mistake here can break system services!

/var - Variable Data

Contains files that change frequently, like logs, caches, and databases. As a web developer, you'll spend time here checking logs.

user@ubuntu:~$ ls /var
backups  cache  lib  local  lock  log  mail  opt  run  spool  tmp  www

user@ubuntu:~$ ls /var/log
apache2  nginx  mysql  syslog  auth.log
Web Development: Web server logs are typically in /var/log/nginx/ or /var/log/apache2/. These are essential for debugging websites.

/usr - User Programs

Contains user-installed programs and their data. This is where most software you install will live.

user@ubuntu:~$ ls /usr
bin  games  include  lib  local  sbin  share  src

user@ubuntu:~$ ls /usr/bin | grep "node\|python\|git"
node  nodejs  python3  git

/tmp - Temporary Files

Temporary files that are deleted on system reboot. Great for temporary storage during development.

user@ubuntu:~$ ls /tmp
ssh-XX123  temp-file.txt  firefox_cache

Special Directories

Some directories contain virtual filesystems that don't exist on disk but represent system information:

/dev - Device Files

Represents hardware devices as files. This is the "everything is a file" philosophy in action!

user@ubuntu:~$ ls /dev | head -10
autofs  block  bsg  btrfs-control  char  console  core  cpu  cpu_dma_latency  cuse

user@ubuntu:~$ ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2
Cool Example: You can read your hard drive directly with cat /dev/sda (though this is not recommended!).

/proc - Process Information

Virtual filesystem showing system and process information. Great for monitoring and debugging.

user@ubuntu:~$ cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 142
model name	: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz

/sys - System Information

Information about system hardware and drivers. More modern than /proc for hardware info.

Web Development Specific Directories

As a web developer, you'll frequently work with these locations:

/var/www - Web Files

Default location for web server files on many systems.

user@ubuntu:~$ ls -la /var/www
drwxr-xr-x 2 root root 4096 Dec 10 10:00 .
drwxr-xr-x 12 root root 4096 Dec 10 09:00 ..
-rw-r--r-- 1 root root 10918 Dec 10 10:00 index.html
-rw-r--r-- 1 root root  1024 Dec 10 09:30 style.css

/etc/nginx or /etc/apache2

Web server configuration files.

user@ubuntu:~$ ls /etc/nginx
conf.d  nginx.conf  sites-available  sites-enabled

Directory Color Coding

When you use ls with colors, different types of files appear in different colors:

📁 Blue
- Directories
📄 Green
- Executable files
📄 Red
- Archive files (.zip, .tar, .gz)
📄 Yellow
- Device files
📄 Purple
- Image files
🔗 Gray
- Symbolic links

Practical Examples

Finding Your Web Server Config

user@ubuntu:~$ find /etc -name "nginx.conf" 2>/dev/null
/etc/nginx/nginx.conf

Checking Web Server Logs

user@ubuntu:~$ tail -f /var/log/nginx/access.log
192.168.1.100 - - [10/Dec/2024:10:30:15 +0000] "GET / HTTP/1.1" 200 10918

Creating a Project Directory

user@ubuntu:~$ mkdir -p $HOME/projects/mywebsite
user@ubuntu:~$ cd $HOME/projects/mywebsite
user@ubuntu:~/projects/mywebsite$ pwd
/home/valente/projects/mywebsite

Key Takeaways

Think About It

Why do you think Linux separates user files (/home) from system files (/etc, /usr)? How does this help with system management and security?

Next: Everything is a File →