{
    "slug": "linux_file_system",
    "term": "Linux File System Hierarchy",
    "category": "linux",
    "difficulty": "beginner",
    "short": "The standard directory structure of Linux — /etc for config, /var for variable data, /tmp for temporary files, /usr for user programs — knowing it prevents misplacing files.",
    "long": "FHS (Filesystem Hierarchy Standard) defines where things go: /etc (config files), /var (variable data — logs, spool, databases), /var/log (logs), /var/www (web content), /tmp (temp files, cleared on reboot), /usr/local (locally installed software), /home (user home dirs), /root (root home), /proc (virtual — kernel and process info), /sys (virtual — hardware info), /run (runtime data, cleared on reboot), /opt (optional/third-party software). PHP apps live in /var/www; logs go to /var/log; runtime files (PID, sockets) go to /run.",
    "aliases": [
        "FHS",
        "directory structure",
        "filesystem hierarchy"
    ],
    "tags": [
        "linux",
        "devops",
        "server"
    ],
    "misconception": "Files can go anywhere as long as they work — non-standard file locations break package managers, backup scripts, log rotation configs, and security policies that assume standard paths.",
    "why_it_matters": "Placing PHP logs in /tmp (cleared on reboot) or PID files in /home (wrong permissions) causes hard-to-diagnose failures; FHS conventions exist so tools can find files reliably.",
    "common_mistakes": [
        "Writing temporary files to the app directory — use sys_get_temp_dir() or /tmp; app directory may not be writable.",
        "Storing uploaded files in /tmp — /tmp is cleared on reboot; use /var/www/uploads or object storage.",
        "Log files in the application root — they should go to /var/log/appname/ for log rotation and access control.",
        "Hardcoding /home/username paths — breaks when deployed as a different user or on a different server."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "linux_file_permissions",
        "cron_jobs",
        "linux_log_files"
    ],
    "prerequisites": [
        "linux_file_permissions",
        "linux_processes",
        "php_fpm"
    ],
    "refs": [
        "https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html"
    ],
    "bad_code": "// Files in wrong locations:\ndefine('LOG_FILE',    '/tmp/app.log');         // Cleared on reboot!\ndefine('UPLOAD_DIR',  '/tmp/uploads/');         // Cleared on reboot!\ndefine('CONFIG_FILE', '/home/paul/app.conf');   // User-specific path\ndefine('PID_FILE',    '/var/www/html/app.pid'); // Wrong — should be /run/",
    "good_code": "// Correct FHS locations:\ndefine('LOG_FILE',    '/var/log/myapp/app.log');\ndefine('UPLOAD_DIR',  '/var/www/myapp/uploads/');  // Persistent\ndefine('CONFIG_FILE', '/etc/myapp/config.php');     // Standard config location\ndefine('PID_FILE',    '/run/myapp/app.pid');        // Standard runtime location\ndefine('CACHE_DIR',   sys_get_temp_dir() . '/myapp_cache/'); // Portable temp",
    "quick_fix": "PHP-FPM runs as www-data — ensure web-served files are owned by www-data or readable by it; never make the entire /var/www writable by www-data as a quick fix",
    "severity": "high",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/linux_file_system",
        "html_url": "https://codeclaritylab.com/glossary/linux_file_system",
        "json_url": "https://codeclaritylab.com/glossary/linux_file_system.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Linux File System Hierarchy](https://codeclaritylab.com/glossary/linux_file_system) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/linux_file_system"
            }
        }
    }
}