DEV Community

Safal Bhattarai
Safal Bhattarai

Posted on

Linux Folder Structure Explained: The Root Directory (/) and /etc

If you are new to Linux, the first thing that feels strange is the folder layout. There is no C:\ drive. Everything starts from a single root directory: /.

This is Part 1 of a series where I walk through the Linux filesystem one directory at a time. In this post we cover the root directory and /etc.

The Filesystem Hierarchy Standard (FHS)

Most Linux distributions follow the Filesystem Hierarchy Standard (FHS), a convention that defines which kind of file lives where. Once you learn it, every Linux server feels familiar.

See it yourself

ls /
Enter fullscreen mode Exit fullscreen mode
bin   boot  dev   etc   home  lib   media
mnt   opt   proc  root  run   sbin  srv
sys   tmp   usr   var
Enter fullscreen mode Exit fullscreen mode

Your output may differ slightly depending on the distribution.

Quick map of /

Directory Purpose
/bin Essential user commands (ls, cp, cat)
/sbin System administration commands
/etc System-wide configuration files
/home Personal folders for regular users
/root Home folder of the root user
/var Variable data: logs, caches, mail
/tmp Temporary files
/usr Installed programs and libraries
/dev Device files
/proc Virtual files with process and kernel information
/boot Bootloader and kernel files
/opt Optional third-party software

On many modern distributions, /bin, /sbin, and /lib are symbolic links to the matching folders inside /usr. You can check with:

ls -ld /bin /sbin /lib
Enter fullscreen mode Exit fullscreen mode

We will cover each of these in later parts.

Deep dive: /etc

/etc holds system-wide configuration files. Most of them are plain text, so you can read them with cat or less and edit them with a text editor.

ls /etc | head -n 10
Enter fullscreen mode Exit fullscreen mode

Important files in /etc

File What it does
/etc/passwd List of user accounts
/etc/group List of groups
/etc/hosts Local hostname to IP mapping
/etc/resolv.conf DNS resolver settings
/etc/fstab Filesystems mounted at boot
/etc/hostname The name of the machine
/etc/ssh/sshd_config SSH server settings
/etc/os-release Distribution name and version

Example 1: Read the hosts file

cat /etc/hosts
Enter fullscreen mode Exit fullscreen mode
127.0.0.1   localhost
127.0.1.1   my-machine
Enter fullscreen mode Exit fullscreen mode

You can map a name to an IP here, which is handy for local testing:

echo "192.168.1.50 myserver.local" | sudo tee -a /etc/hosts
Enter fullscreen mode Exit fullscreen mode

Example 2: Check your Linux distribution

cat /etc/os-release
Enter fullscreen mode Exit fullscreen mode
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
Enter fullscreen mode Exit fullscreen mode

Example 3: See user accounts

cut -d: -f1 /etc/passwd | head -n 5
Enter fullscreen mode Exit fullscreen mode
root
daemon
bin
sys
sync
Enter fullscreen mode Exit fullscreen mode

Each line in /etc/passwd has fields separated by colons: username, password placeholder, user ID, group ID, description, home directory, and shell. Despite the name, real password hashes are stored in /etc/shadow, which only root can read.

Example 4: Check DNS settings

cat /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

This shows which DNS servers your system uses. It connects nicely to the dig and nslookup posts in my Linux Networking Commands series.

Good practice when editing /etc

  1. Back up first: sudo cp /etc/hosts /etc/hosts.bak
  2. Use sudo only when you really need it.
  3. Validate the config when the tool supports it, for example sudo sshd -t for SSH.
  4. Never delete files in /etc unless you know exactly what they do.

Summary

  • / is the top of the whole directory tree.
  • Each top-level directory has a specific purpose defined by the FHS.
  • /etc stores system configuration, mostly as editable text files.
  • Always back up before you change anything.

Next in the series: Part 2, /home, /root, and /tmp.

Did I miss anything or get something wrong? Leave a comment below.

Top comments (0)