Linux directories and logs cheat sheet
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.
-
/etcConfiguration 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.
-
/homeThe home directories of regular users, for example /home/user.
-
/rootThe home directory of the root user. It is separate from /home, so root can log in even when /home isn't available.
-
/usrPrograms 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.
-
/binOn 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/localSoftware 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.
-
/optAdditional third-party software packages, each installed in its own directory, for example /opt/example.
-
/srvData served by the server, for example website or FTP files. The server administrator decides its structure, and many distributions leave it empty.
-
/varData 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.
-
/tmpSmall 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/tmpTemporary 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.
-
/bootThe kernel and the system boot files. Caution: deleting or changing files in this directory can prevent the server from booting.
-
/runRuntime 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.
-
/mntA temporary mount point for a file system, for example an extra disk during maintenance.
-
/mediaMount points for removable media, such as a USB drive or a CD.
Important directories in /var
-
/var/logSystem and service logs. Each service usually has its own file or subdirectory.
-
/var/libPersistent data of programs and services, for example the package manager state. Caution: don't delete files from it to free up space.
-
/var/lib/mysqlThe 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/cacheProgram 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/spoolQueues of jobs waiting to be processed, for example outgoing mail, print jobs, and scheduled tasks.
-
/var/spool/cronThe 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/wwwThe 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
-
/procA 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/cpuinfoShows the processor and core details.
-
cat /proc/meminfoShows a detailed breakdown of the memory status. The free -h command shows the main figures in a more readable form.
-
/sysA virtual file system (sysfs) with structured information about devices, drivers, and kernel settings.
-
/devDevice files, such as disks (/dev/sda, /dev/vda, or /dev/nvme0n1) and terminals. The kernel and udev create them automatically.
-
/dev/nullA 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-releaseShows the distribution name and version.
-
/etc/hostsManual 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/fstabThe 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/passwdThe list of users on the system. The passwords themselves are stored hashed in /etc/shadow, which only root can read.
-
/etc/ssh/sshd_configThe 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/crontabSystem-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/systemsystemd 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/syslogThe 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/messagesThe general system log on Red Hat family distributions, such as RHEL, AlmaLinux, and Rocky Linux.
-
/var/log/auth.logLogins, sudo, and SSH on Ubuntu, and on Debian when rsyslog is installed.
-
/var/log/secureLogins, sudo, and SSH on Red Hat family distributions.
-
/var/log/kern.logKernel 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/croncron job runs on Red Hat family distributions. On Ubuntu, these messages are written to /var/log/syslog.
-
/var/log/journalThe 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.logThe apt command history on Debian and Ubuntu: when each command ran and which packages were installed, upgraded, or removed.
-
/var/log/apt/term.logThe full output shown on screen during apt installs and upgrades.
-
/var/log/dpkg.logEvery 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.logThe 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.logThe Apache error log on Debian and Ubuntu. The access log is in the same directory, named access.log.
-
/var/log/httpd/error_logThe Apache error log on Red Hat family distributions. The access log is in the same directory, named access_log.
-
/var/log/nginx/error.logThe 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.logThe 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/maillogThe mail log on Red Hat family distributions: sending, receiving, and mailbox logins.
-
/var/log/mail.logThe 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/messagesShows the last 100 lines of the log.
-
sudo tail -f /var/log/nginx/error.logFollows the log in real time and shows every new line. Press Ctrl+C to exit.
-
sudo tail -F /var/log/nginx/access.logLike 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/messagesOpens 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.logShows the lines that contain error, ignoring case.
-
sudo grep -i -C 3 "timeout" /var/log/messagesShows 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.logShows failed SSH login attempts on Ubuntu. On Red Hat family distributions, search /var/log/secure.
-
ls -lt /var/logLists the logs by modification time, newest first, to see which logs are being updated right now.
-
sudo du -sh /var/log/* | sort -hShows the size of each log and directory in /var/log, sorted from smallest to largest.
journalctl
-
sudo journalctl -eOpens the journal and jumps to the end, to the latest messages.
-
sudo journalctl -fShows new messages from all services in real time. Press Ctrl+C to exit.
-
sudo journalctl -u ssh -n 50Shows 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 -bShows errors and more severe messages since the last boot.
-
sudo journalctl --list-bootsLists the boots saved in the journal. When the journal is kept in memory only, just the current boot appears.
-
sudo journalctl -b -1Shows 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-usageShows how much space the systemd journal files take up.
-
sudo mkdir -p /var/log/journal && sudo systemctl restart systemd-journaldTurns 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.confThe 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.dA 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 | lessA 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/statusThe 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.
No matching items.
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.
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 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.