Linux filesystem hierarchy and essential paths

Topic: Servers linux

Summary

Learn the standard Linux directory layout: /etc for config, /var for variable data, /home for users, /tmp for temporary files. Find where config, logs, and binaries live so you can back up, restore, and troubleshoot without guessing.

Intent: How-to

Quick answer

  • /etc holds system and service config; /var holds logs, caches, and variable data; /home is user home dirs; /usr and /opt hold applications.
  • Use find, locate, or whereis to find config and binaries; check /etc for service names and /var/log for logs.
  • When backing up or migrating, include /etc and /var (and /home if needed); avoid restoring over a running system without a plan.

Prerequisites

Steps

  1. Know the main directories

    Memorize: /etc config, /var/log logs, /var/lib persistent app data, /home users, /tmp and /var/tmp temp, /usr/bin and /usr/sbin binaries, /opt optional software.

  2. Find config and data for a service

    Look in /etc for a dir or file named after the service (e.g. /etc/nginx); check the service unit or init script for paths; check /var/lib and /var/log for data and logs.

  3. Locate binaries and man pages

    Run which cmd or whereis cmd; use find /usr -name 'cmd' or locate cmd (after updatedb) to find executables and related files.

  4. Use paths in backup and restore

    Back up /etc and /var (exclude large caches if needed) and application dirs under /opt or /home; document what you excluded so restore is consistent.

Summary

You will learn the standard Linux filesystem layout and where config, logs, and binaries live. Use this to find files quickly, plan backups, and fix broken configs or missing paths.

Prerequisites

  • Shell access to a Linux system.
  • Basic use of ls and cd.

Steps

Step 1: Know the main directories

  • /etc — System and service configuration. Do not store large data here.
  • /var — Variable data: /var/log (logs), /var/lib (DBs, app state), /var/cache (cache), /var/tmp (persistent temp).
  • /home — User home directories.
  • /usr — Userland software: /usr/bin, /usr/sbin, /usr/lib; read-only after install.
  • /opt — Optional or third-party software.
  • /tmp — Temporary files (often cleared on reboot).

Step 2: Find config and data for a service

ls /etc/nginx
systemctl show nginx --property=FragmentPath
grep -r ExecStart /etc/systemd/system /lib/systemd/system

Inspect the unit file or init script for WorkingDirectory, config paths, and data dirs; then list /var/lib and /var/log for that service.

Step 3: Locate binaries and man pages

which nginx
whereis nginx
type nginx
locate nginx  # if updatedb is run

Use find /usr -name 'nginx' if locate is not available. Man pages: man -w section name.

Step 4: Use paths in backup and restore

  • Include /etc and /var (minus /var/cache if desired) in backups; add /opt and /home as needed.
  • Document exclusions (e.g. /var/log/*.gz, /tmp) so restores are predictable. Test restore to a scratch dir before relying on it.

Verification

  • You can name the purpose of /etc, /var, /home, /usr, /opt, /tmp; you found the config and log paths for at least one service; backup list matches your restore test.

Troubleshooting

Config change had no effect — Service may use a different path (check unit file or —config); you may have edited the wrong file; restart or reload the service after editing.

Disk full in /var — Identify large dirs with du (e.g. /var/log, /var/cache); rotate or remove logs, clear caches; consider moving data to another filesystem.

Next steps

Continue to