Linux directories and logs cheat sheet

This cheat sheet brings together the main directories on a Linux server and the log locations on different distributions, along with the commands for reading logs, journalctl, and logrotate. You can search for a path or command, filter by topic, and copy it with one click.

Main directories

  • /

    The root directory. Every file and directory on the system sits below it, even when they are stored on separate disks or partitions.

  • /etc

    Configuration files for the system and the installed services, for example /etc/ssh for the SSH settings. We recommend keeping a copy of a file before you edit it.

  • /home

    The home directories of regular users, for example /home/user.

  • /root

    The home directory of the root user. It is separate from /home, so root can log in even when /home isn't available.

  • /usr

    Programs and files that come with the distribution and with software packages: commands in /usr/bin, libraries in /usr/lib, and documentation in /usr/share. The package manager owns the contents, and updates may overwrite manual changes.

  • /bin

    On current distributions, /bin is a symbolic link to /usr/bin, and so are /sbin and /lib, which point to the matching directories inside /usr (the /usr merge). On older distributions, these are separate directories with the basic commands for starting the system.

  • /usr/local

    Software that the server administrator installs directly, not through the package manager, for example a program built from source code. Distribution updates don't overwrite its contents.

  • /opt

    Additional third-party software packages, each installed in its own directory, for example /opt/example.

  • /srv

    Data served by the server, for example website or FTP files. The server administrator decides its structure, and many distributions leave it empty.

  • /var

    Data that changes while the system is running: logs, databases, cache, and queues. Keep an eye on its size, because logs and databases grow over time.

  • /tmp

    Small temporary files. On many distributions, it is kept in memory (tmpfs) and emptied at boot, and files that haven't been used for a while are deleted automatically. Don't keep files you need there.

  • /var/tmp

    Temporary files that are kept across reboots, suited to files larger than those in /tmp. Old files that haven't been used may also be deleted automatically here.

  • /boot

    The kernel and the system boot files. Caution: deleting or changing files in this directory can prevent the server from booting.

  • /run

    Runtime data since the last boot, such as PID files and service sockets. It is kept in memory, emptied at every boot, and replaces /var/run.

  • /mnt

    A temporary mount point for a file system, for example an extra disk during maintenance.

  • /media

    Mount points for removable media, such as a USB drive or a CD.

Important directories in /var

  • /var/log

    System and service logs. Each service usually has its own file or subdirectory.

  • /var/lib

    Persistent data of programs and services, for example the package manager state. Caution: don't delete files from it to free up space.

  • /var/lib/mysql

    The MySQL and MariaDB data directory when installed from the distribution packages. Back it up with mysqldump or a dedicated backup tool, not by copying the files while the service is running.

  • /var/cache

    Program cache, for example the package manager cache. Deleting the contents doesn't break the programs, which rebuild it, but until then they may run more slowly.

  • /var/spool

    Queues of jobs waiting to be processed, for example outgoing mail, print jobs, and scheduled tasks.

  • /var/spool/cron

    The users' crontab files on Red Hat family distributions. On Debian and Ubuntu, they are in /var/spool/cron/crontabs. Edit them only with crontab -e.

  • /var/www

    The usual directory for website files when the web server is installed from the distribution packages. With Apache from Ubuntu and Red Hat family packages, the default website directory is /var/www/html.

Virtual file systems and devices

  • /proc

    A virtual file system that the kernel creates, with information about the running processes and the system. The files aren't stored on disk and take up no space.

  • cat /proc/cpuinfo

    Shows the processor and core details.

  • cat /proc/meminfo

    Shows a detailed breakdown of the memory status. The free -h command shows the main figures in a more readable form.

  • /sys

    A virtual file system (sysfs) with structured information about devices, drivers, and kernel settings.

  • /dev

    Device files, such as disks (/dev/sda, /dev/vda, or /dev/nvme0n1) and terminals. The kernel and udev create them automatically.

  • /dev/null

    A device that discards everything written to it. It is used to silence a command's output, for example by adding > /dev/null 2>&1 at the end of a cron job.

Important files in /etc

  • cat /etc/os-release

    Shows the distribution name and version.

  • /etc/hosts

    Manual mapping of names to IP addresses, which usually takes precedence over DNS. Useful on your local computer to test a website on a new server before you change the DNS.

  • /etc/fstab

    The file systems that are mounted automatically at boot. Caution: a wrong line can prevent the server from booting, so check with sudo findmnt --verify before you reboot.

  • /etc/passwd

    The list of users on the system. The passwords themselves are stored hashed in /etc/shadow, which only root can read.

  • /etc/ssh/sshd_config

    The SSH server settings. On current distributions, you add settings in separate files in the /etc/ssh/sshd_config.d directory. After a change, check the syntax with sudo sshd -t, and only then restart the service.

  • /etc/crontab

    System-wide scheduled tasks, with an extra column for the name of the user that runs the command. More tasks are in /etc/cron.d and in directories such as /etc/cron.daily.

  • /etc/systemd/system

    systemd unit files that the server administrator creates or changes. They take precedence over the files that come with packages in /usr/lib/systemd/system.

System logs by distribution

  • /var/log/syslog

    The general system log on Ubuntu. On recent Debian releases, rsyslog isn't installed by default and the file doesn't exist: read the logs with journalctl, or install the rsyslog package.

  • /var/log/messages

    The general system log on Red Hat family distributions, such as RHEL, AlmaLinux, and Rocky Linux.

  • /var/log/auth.log

    Logins, sudo, and SSH on Ubuntu, and on Debian when rsyslog is installed.

  • /var/log/secure

    Logins, sudo, and SSH on Red Hat family distributions.

  • /var/log/kern.log

    Kernel messages on Ubuntu, and on Debian when rsyslog is installed. On any distribution, you can also read them with sudo journalctl -k or sudo dmesg -T.

  • /var/log/cron

    cron job runs on Red Hat family distributions. On Ubuntu, these messages are written to /var/log/syslog.

  • /var/log/journal

    The systemd journal (journald) in persistent storage on disk, in a binary format that you read with journalctl. When the directory doesn't exist and the Storage setting is auto, the journal is kept in memory in /run/log/journal and deleted at boot.

Install and update logs

  • /var/log/apt/history.log

    The apt command history on Debian and Ubuntu: when each command ran and which packages were installed, upgraded, or removed.

  • /var/log/apt/term.log

    The full output shown on screen during apt installs and upgrades.

  • /var/log/dpkg.log

    Every dpkg action on packages, including the version before and after the upgrade.

  • zgrep " install " /var/log/dpkg.log*

    Shows the packages that were installed, in the current log and in its older versions.

  • /var/log/dnf.log

    The dnf activity log on Red Hat family distributions. The list of packages that were installed, upgraded, or removed, with date and time, is in /var/log/dnf.rpm.log.

Web server and mail logs

  • /var/log/apache2/error.log

    The Apache error log on Debian and Ubuntu. The access log is in the same directory, named access.log.

  • /var/log/httpd/error_log

    The Apache error log on Red Hat family distributions. The access log is in the same directory, named access_log.

  • /var/log/nginx/error.log

    The Nginx error log in the distribution packages, for example on Ubuntu. The access log is in the same directory, named access.log.

  • /usr/local/nginx/logs/error.log

    The location of the Nginx error log when built from source code with the default settings. The access log is in the same directory, named access.log.

  • /var/log/maillog

    The mail log on Red Hat family distributions: sending, receiving, and mailbox logins.

  • /var/log/mail.log

    The mail log on Ubuntu, and on Debian when rsyslog is installed. On Ubuntu, errors alone are also written to /var/log/mail.err.

Reading logs

  • sudo tail -n 100 /var/log/messages

    Shows the last 100 lines of the log.

  • sudo tail -f /var/log/nginx/error.log

    Follows the log in real time and shows every new line. Press Ctrl+C to exit.

  • sudo tail -F /var/log/nginx/access.log

    Like tail -f, and keeps following even after log rotation (logrotate) replaces the file with a new file of the same name.

  • sudo less +F /var/log/messages

    Opens the log in less in follow mode. Ctrl+C stops following so you can scroll and search with /, the F key resumes following, and q quits.

  • sudo grep -i "error" /var/log/nginx/error.log

    Shows the lines that contain error, ignoring case.

  • sudo grep -i -C 3 "timeout" /var/log/messages

    Shows each match with 3 lines before it and 3 lines after it, so you can see the context.

  • sudo zgrep -i "error" /var/log/nginx/error.log*

    Searches the current log and all its older versions at once, including those compressed with gzip.

  • sudo grep "Failed password" /var/log/auth.log

    Shows failed SSH login attempts on Ubuntu. On Red Hat family distributions, search /var/log/secure.

  • ls -lt /var/log

    Lists the logs by modification time, newest first, to see which logs are being updated right now.

  • sudo du -sh /var/log/* | sort -h

    Shows the size of each log and directory in /var/log, sorted from smallest to largest.

journalctl

  • sudo journalctl -e

    Opens the journal and jumps to the end, to the latest messages.

  • sudo journalctl -f

    Shows new messages from all services in real time. Press Ctrl+C to exit.

  • sudo journalctl -u ssh -n 50

    Shows the last 50 messages of the SSH service. On Debian and Ubuntu, the service name is ssh, and on Red Hat family distributions it is sshd.

  • sudo journalctl -u nginx --since "1 hour ago"

    Shows the messages of a service from the last hour.

  • sudo journalctl -p err -b

    Shows errors and more severe messages since the last boot.

  • sudo journalctl --list-boots

    Lists the boots saved in the journal. When the journal is kept in memory only, just the current boot appears.

  • sudo journalctl -b -1

    Shows the messages from the previous boot, for example to find out why the server restarted unexpectedly. Requires persistent journal storage on disk.

  • sudo journalctl -k -g "out of memory"

    Searches the kernel messages for processes that were killed because memory ran out. A search pattern in all lowercase is case-insensitive.

  • journalctl --disk-usage

    Shows how much space the systemd journal files take up.

  • sudo mkdir -p /var/log/journal && sudo systemctl restart systemd-journald

    Turns on persistent journal storage on disk when the Storage setting in /etc/systemd/journald.conf is auto. When it is volatile, change it to persistent.

Log rotation (logrotate)

  • /etc/logrotate.conf

    The general logrotate settings: how often to rotate, how many old versions to keep, and whether to compress them. The include /etc/logrotate.d line loads the settings of the services.

  • /etc/logrotate.d

    A separate settings file for each service, for example /etc/logrotate.d/nginx. A setting in a service file overrides the general setting.

  • sudo logrotate -d /etc/logrotate.conf 2>&1 | less

    A dry run: shows what logrotate would do, without changing the logs or the state file. Useful for checking the settings after you edit them.

  • /var/lib/logrotate/status

    The state file, with the time of the last rotation of each log, on Debian and Ubuntu. On Red Hat family distributions, it is at /var/lib/logrotate/logrotate.status.

Where to start when something isn't working

When a service fails to start, begin with systemctl status and the service name, and continue with sudo journalctl -u and the same name to see the full messages. When a website returns an error, check the web server's error log, not the access log, which records only the requests. On a server with a control panel, website logs are usually kept in the panel's own paths, which are listed on the Control panel paths, ports, and logs page.

Why the /var/log/syslog file is missing

On recent Debian releases, rsyslog isn't installed by default, so text logs such as syslog and auth.log aren't created. The messages are kept in the systemd journal, and you read them with journalctl: sudo journalctl -e instead of opening syslog, and sudo journalctl -f instead of tail -f /var/log/syslog. If you need the text files, install the rsyslog package.

Did you know?

On a Linux VPS, you connect over SSH with full root access and read every log on the server with the commands on this page.

Linux VPS plans

Linux directories and logs FAQ

Where are the log files on a Linux server?

Most logs are in the /var/log directory. The general log is /var/log/syslog on Ubuntu and /var/log/messages on Red Hat family distributions, and logins are recorded in /var/log/auth.log or /var/log/secure, respectively. Web servers keep their logs in a directory of their own, for example /var/log/nginx, and on any distribution with systemd you can read the messages of every service with journalctl.

How do I view a log in real time?

The sudo tail -f command with the log path shows every new line as soon as it is written, and tail -F keeps following even after log rotation. For the systemd journal, use sudo journalctl -f, or for example sudo journalctl -u nginx -f to follow a single service. Press Ctrl+C to stop following.

Why is there no /var/log/syslog file on a Debian server?

On recent Debian releases, rsyslog isn't installed by default, so the syslog, auth.log, and kern.log text files aren't created. All messages are kept in the systemd journal, and you read them with journalctl, for example sudo journalctl -e for the latest messages. If you prefer text files, you can install the rsyslog package.

What is the difference between /tmp and /var/tmp?

The /tmp directory is meant for small temporary files, and on many distributions it is kept in memory and emptied at every boot. The /var/tmp directory is stored on disk, its files are kept across reboots, and it suits larger temporary files. In both directories, old files that haven't been used may be deleted automatically, so don't keep important data in them.

How do I keep logs from filling up the disk?

The logrotate tool rotates logs by time or size, can compress the old versions, and deletes the oldest ones, based on the settings in /etc/logrotate.conf and /etc/logrotate.d. For the systemd journal, you set a size limit with the SystemMaxUse setting in /etc/systemd/journald.conf. To see what takes up space, run sudo du -sh /var/log/* | sort -h and journalctl --disk-usage.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement