4.6.2. Traditional logs in /var/log
Table of Contents
Location and Purpose of `/var/log`
On a traditional Linux system, most system and application logs are stored as plain text files under the directory /var/log. The /var part indicates "variable" data, which can grow and change frequently, and log is specifically for logging information.
Log files in /var/log record what the system and its services are doing over time. They are essential when you need to investigate problems, check security events, or simply understand how your system behaves.
Logs in /var/log are one of your primary tools for troubleshooting and security investigations on a Linux system.
The directory is usually readable only by the root user or specific system groups, because logs can contain sensitive information such as IP addresses, usernames, or even parts of configuration data.
Structure of the `/var/log` Directory
Although exact contents vary by distribution and by which services are installed, some common patterns appear in /var/log.
Most distributions keep a set of core system logs directly inside /var/log, such as syslog or messages, authentication logs, kernel logs, and boot logs. In addition to these, many services have their own subdirectories. For example, web servers often log to /var/log/apache2 or /var/log/httpd, and mail servers log under /var/log/mail or similar paths.
This layout lets you quickly narrow down where to look. When troubleshooting a specific service, you typically first check its dedicated directory under /var/log before looking at the more general system logs.
Key System Log Files
Several files in /var/log are especially important for everyday administration. The exact names are distribution dependent, but the roles are consistent across systems.
On Debian based systems, such as Ubuntu, you usually find a file called /var/log/syslog that collects general system messages from many services. On Red Hat based systems, such as Fedora or CentOS, the equivalent is usually /var/log/messages. When you suspect a general problem that is not obviously tied to a specific service, this kind of file is often your first stop.
Authentication related events, such as logins, failed login attempts, and sudo use, are typically recorded centrally. On Debian based systems, this is often /var/log/auth.log. On Red Hat based systems, you frequently see /var/log/secure performing a similar role. These logs are central when you investigate suspected unauthorized access or when you need to verify that authentication is working correctly.
Kernel specific messages, such as hardware detection, driver issues, or kernel warnings, may appear in a dedicated kernel log file like /var/log/kern.log or may be merged into the main system log, depending on configuration. When you suspect an issue with hardware or drivers, kernel logs are particularly valuable.
Boot messages may also be recorded in a separate boot log file, such as /var/log/boot.log, recording messages that appear during system startup. This can be helpful when you want to see what happened at boot time, especially if there were delays or failures.
Many other service specific logs reside in /var/log as well, such as mail.log for mail transport, cron.log for scheduled tasks, and dpkg.log or yum.log for package management actions, depending on your distribution.
Accessing and Reading Log Files
Since most files in /var/log are plain text, you can use standard text viewing tools to inspect them. Utilities such as cat, less, and tail are frequently used. In general, you read /var/log files as root, either by logging in as root or by using sudo with your viewer.
If you want to read an entire log file, you can use less for convenient scrolling and searching. For example:
sudo less /var/log/syslog
Within less, you can move line by line or page by page, and you can search with /pattern. This makes it easy to navigate large log files. less does not modify the file, it only reads it.
If you only need the last few lines of a log, such as when you are watching for a recent error, tail is useful. To see the last 20 lines of a file, you can run:
sudo tail -n 20 /var/log/auth.log
When you need to watch a log file as it updates, for example while restarting a service and looking for fresh error messages, you can follow the file with tail -f:
sudo tail -f /var/log/syslog
This command keeps running and prints new lines as they are written by the system. You can stop it with Ctrl+C.
You can also search within logs for specific patterns using tools like grep. An example is:
sudo grep "error" /var/log/syslog
This shows only lines containing the word error in the specified log.
Permissions and Security Considerations
Because log files can contain sensitive details, access is usually restricted. Ordinary users may not have permission to read most files under /var/log. As an administrator, you typically access them via sudo. If you list the directory with:
ls -l /var/log
you can see the owner, group, and permissions of each file and directory. Logs are often owned by root or by a specific service user, and may belong to a dedicated group such as adm or syslog, which can grant read access to certain administrative users without giving them full root access.
You should resist the temptation to relax permissions on log files for convenience. Making logs world readable can expose security information. Similarly, log files should not be writable by ordinary users. If a user can modify logs, they can hide their actions or inject misleading entries.
Some services rotate logs and change ownership or permissions as new files are created. For example, a web server log may be owned by the service user that runs the web server. When you inspect such logs, you may still need sudo if your user does not belong to the relevant group.
Never grant write access on critical logs in /var/log to untrusted users. Writable logs undermine the integrity of your auditing and troubleshooting data.
Log Rotation and File Naming Patterns
Traditionally, log files in /var/log are not allowed to grow indefinitely. Instead, a log rotation system periodically archives older logs and truncates or recreates the active log file. On many systems, this is managed by logrotate, which is typically configured in /etc/logrotate.conf and /etc/logrotate.d/.
When log rotation is used, you will see file naming patterns that indicate rotated logs. A current log file may be named /var/log/syslog, and older versions may appear as /var/log/syslog.1, /var/log/syslog.2.gz, and so on. The .1 file usually holds the previous period, and higher numbers hold older data. The .gz suffix indicates that the log has been compressed using gzip to save disk space.
Rotation is usually driven by size, time, or a combination. For example, logs may rotate once per day, or when they reach a certain number of megabytes, or both. When retention policies are applied, older rotated logs are eventually deleted after a configured number of rotations.
From an administrator’s perspective, this means that when you investigate an incident that happened some time ago, you may need to look into the rotated and possibly compressed logs. To read a compressed log, you can either decompress it with gunzip or use tools like zless and zgrep that read gzip compressed files directly. For example:
sudo zless /var/log/syslog.3.gzWhen you know roughly when an event occurred, the date of rotation and the numbering pattern help you identify which file to inspect.
Service Specific Logs in `/var/log`
Beyond the central system and authentication logs, many individual services maintain their own log files or log directories under /var/log. Experienced administrators often go directly to these service specific logs when diagnosing a problem with a particular component.
Web servers are a typical example. Apache HTTP Server, depending on the distribution, logs to a directory like /var/log/apache2 or /var/log/httpd. Inside you may find separate access.log and error.log files. access.log records details of HTTP requests, such as client IPs and requested URLs, while error.log contains warnings, configuration errors, and runtime problems for the web server itself.
Mail transport agents, such as Postfix or Exim, also maintain detailed logs. These might live in files like /var/log/mail.log, /var/log/maillog, or in service specific directories. When investigating mail delivery issues, bounces, or spam filtering behavior, these logs are the primary reference.
Task schedulers, such as cron, may log their activities to a file like /var/log/cron or cron.log. This can be crucial when a scheduled job does not seem to run as expected and you need to confirm whether the job was triggered and what the outcome was.
Database servers, such as MySQL or PostgreSQL, often have their own logs as well. These may be placed under /var/log/mysql, /var/log/mariadb, or /var/log/postgresql, depending on how the service was packaged for your distribution. You inspect these files when you need to understand connection failures, query errors, or startup problems for the database server.
Each service can choose its own logging format and level of detail. Some log plain text, some log structured data. They also often control how verbose they are through their own configuration files, which determine whether they log only critical errors or also warnings, informational messages, or debug level details.
Practical Use of `/var/log` for Troubleshooting
In everyday administration, the traditional logs in /var/log are a core part of your troubleshooting routine. When a user reports that a service is not working, or when you notice an error in system behavior, you typically use a series of steps that revolve around these logs.
You first identify which component is involved. If the problem is system wide or not clearly linked to a single service, you look at the main system log file such as /var/log/syslog or /var/log/messages. You check recent entries using tail or less, and you may search for relevant words such as fail, error, or the name of a service.
If the issue seems related to authentication, for example the user cannot log in or sudo fails, you focus on /var/log/auth.log or /var/log/secure. These logs can show you whether login attempts reached the system, whether they were denied, and why. Patterns such as repeated failed logins can also indicate brute force attempts from remote hosts.
When you restart a specific service that behaves unexpectedly, you often watch its logs in real time. You open one terminal, run sudo tail -f on the relevant log file, and in another terminal you restart the service. New log entries that appear while the service starts often provide direct clues, such as missing configuration files, permission errors, or port conflicts.
If the problem occurred in the past, you might need to check older logs. In this case, you inspect rotated files and possibly compressed archives in /var/log, based on the timeframe. For example, if an incident happened several days ago, and your logs rotate daily, you might check syslog.1, syslog.2.gz, and so on, until you cover the desired period.
Through repeated use, you develop an intuition for which logs to inspect first, how to search them quickly, and how to correlate entries from different log files, such as matching timestamps between an authentication failure and a network error. The traditional logs in /var/log provide a foundational, historical record that supports this investigative work.
Views: 0
Where to Move
Move chapter:
- ☰ 1. PART I — Linux Fundamentals (Beginner)
- ☰ 1.1. What Is Linux?
- ☰ 1.1.1. What is an operating system
- ☰ 1.1.2. History of Unix and Linux
- ☰ 1.1.3. The Linux kernel
- ☰ 1.1.4. GNU and the Free Software Foundation
- ☰ 1.1.5. Open source philosophy
- ☰ 1.1.6. Where Linux is used today
- ☰ 1.1.7. Desktop vs server vs embedded Linux
-
- ☰ 1.2. Choosing a Linux Distribution
- ☰ 1.2.1. What is a distribution?
- ☰ 1.2.2. Package formats (deb, rpm, pacman)
- ☰ 1.2.3. Popular distributions
- ☰ 1.2.3.1. Ubuntu
- ☰ 1.2.3.2. Debian
- ☰ 1.2.3.3. Fedora
- ☰ 1.2.3.4. Arch Linux
- ☰ 1.2.3.5. openSUSE
-
- ☰ 1.2.4. Rolling vs fixed release
- ☰ 1.2.5. Choosing the right distribution
-
- ☰ 1.3. Installing Linux
- ☰ 1.3.1. Creating a bootable USB
- ☰ 1.3.2. Installing on real hardware
- ☰ 1.3.3. Dual booting with Windows
- ☰ 1.3.4. Installing in a virtual machine
- ☰ 1.3.5. Partitioning
- ☰ 1.3.5.1. `/` (root)
- ☰ 1.3.5.2. `/home`
- ☰ 1.3.5.3. Swap
-
- ☰ 1.3.6. First-time setup
-
- ☰ 1.4. First Steps After Installation
- ☰ 1.4.1. Desktop environment basics
- ☰ 1.4.2. Updating the system
- ☰ 1.4.3. Installing essential tools
- ☰ 1.4.4. Setting up drivers
- ☰ 1.4.5. Using the software center
-
- ☰ 1.5. Linux Filesystem Hierarchy
- ☰ 1.5.1. Overview of the root filesystem
- ☰ 1.5.2. Important directories
- ☰ 1.5.2.1. `/etc`
- ☰ 1.5.2.2. `/var`
- ☰ 1.5.2.3. `/usr`
- ☰ 1.5.2.4. `/tmp`
- ☰ 1.5.2.5. `/dev`
- ☰ 1.5.2.6. `/proc`
- ☰ 1.5.2.7. `/sys`
-
- ☰ 1.5.3. File types
- ☰ 1.5.4. Absolute vs relative paths
-
- ☰ 1.6. The Linux Graphical Environment
- ☰ 1.6.1. GNOME
- ☰ 1.6.2. KDE Plasma
- ☰ 1.6.3. XFCE
- ☰ 1.6.4. File managers
- ☰ 1.6.5. System settings
- ☰ 1.6.6. Workspaces and window management
-
-
- ☰ 2. PART II — Command Line Essentials
- ☰ 2.1. Terminal and Shell Basics
- ☰ 2.1.1. What is a shell?
- ☰ 2.1.2. Bash vs Zsh vs Fish
- ☰ 2.1.3. Command structure
- ☰ 2.1.4. Environment variables
- ☰ 2.1.5. Getting help
- ☰ 2.1.6. Command history and autocomplete
-
- ☰ 2.2. Files and Directories
- ☰ 2.2.1. Listing files
- ☰ 2.2.2. Navigating directories
- ☰ 2.2.3. File operations
- ☰ 2.2.4. Wildcards and globbing
- ☰ 2.2.5. Searching files
-
- ☰ 2.3. Viewing and Editing Text Files
- ☰ 2.3.1. Viewing tools
- ☰ 2.3.2. Editing with nano
- ☰ 2.3.3. Introduction to vim
- ☰ 2.3.4. Input/output redirection
-
- ☰ 2.4. Users, Permissions, and Ownership
- ☰ 2.4.1. Users and groups
- ☰ 2.4.2. Permission types (r, w, x)
- ☰ 2.4.3. Changing permissions
- ☰ 2.4.4. Changing ownership
- ☰ 2.4.5. Using sudo
-
- ☰ 2.5. Package Management
- ☰ 2.5.1. Software repositories
- ☰ 2.5.2. APT (Debian/Ubuntu)
- ☰ 2.5.3. DNF (Fedora/RHEL)
- ☰ 2.5.4. Pacman (Arch Linux)
- ☰ 2.5.5. Snap, Flatpak, AppImage
- ☰ 2.5.6. System upgrades
-
- ☰ 2.6. Working with Processes
- ☰ 2.6.1. What is a process?
- ☰ 2.6.2. Viewing processes
- ☰ 2.6.3. Killing processes
- ☰ 2.6.4. Foreground and background jobs
- ☰ 2.6.5. System services and daemons
-
- ☰ 2.7. Introduction to Shell Scripting
- ☰ 2.7.1. Writing your first script
- ☰ 2.7.2. Variables
- ☰ 2.7.3. Conditionals
- ☰ 2.7.4. Loops
- ☰ 2.7.5. Functions
- ☰ 2.7.6. Making scripts executable
-
-
- ☰ 3. PART III — Intermediate System Administration
- ☰ 3.1. Systemd and Service Management
- ☰ 3.1.1. What is systemd?
- ☰ 3.1.2. Managing services (systemctl)
- ☰ 3.1.3. Boot targets
- ☰ 3.1.4. System logs (journalctl)
- ☰ 3.1.5. Creating custom services
-
- ☰ 3.2. Storage and Filesystems
- ☰ 3.2.1. Devices and partitions
- ☰ 3.2.2. Filesystems (EXT4, XFS, Btrfs)
- ☰ 3.2.3. Mounting and unmounting
- ☰ 3.2.4. Disk usage tools
- ☰ 3.2.5. Archiving and compression (tar, gzip, xz)
-
- ☰ 3.3. Networking Fundamentals
- ☰ 3.3.1. IP addressing
- ☰ 3.3.2. Subnets and routing
- ☰ 3.3.3. DNS and hostnames
- ☰ 3.3.4. Networking tools (ip, ss, ping)
- ☰ 3.3.5. Editing network configuration files
-
- ☰ 3.4. User and Group Administration
- ☰ 3.4.1. User information files
- ☰ 3.4.2. Creating and removing users
- ☰ 3.4.3. Password policies
- ☰ 3.4.4. Managing groups
- ☰ 3.4.5. Shell configuration
-
- ☰ 3.5. System Monitoring
- ☰ 3.5.1. CPU and memory monitoring
- ☰ 3.5.2. Disk and I/O monitoring
- ☰ 3.5.3. Log files in /var/log
- ☰ 3.5.4. Boot performance
- ☰ 3.5.5. Monitoring running services
-
- ☰ 3.6. Backup and Restore
- ☰ 3.6.1. Backup strategies
- ☰ 3.6.2. Using rsync
- ☰ 3.6.3. Creating tar archives
- ☰ 3.6.4. Using snapshot systems
- ☰ 3.6.5. Automating backups
-
- ☰ 3.7. Basic System Security
- ☰ 3.7.1. Firewalls (UFW, firewalld)
- ☰ 3.7.2. Authentication policies
- ☰ 3.7.3. SSH security basics
- ☰ 3.7.4. SELinux and AppArmor overview
- ☰ 3.7.5. Intrusion detection basics
-
-
- ☰ 4. PART IV — Advanced Linux Skills
- ☰ 4.1. Advanced Shell Scripting
- ☰ 4.1.1. Script structure
- ☰ 4.1.2. Error handling
- ☰ 4.1.3. Debugging scripts
- ☰ 4.1.4. Scheduled tasks (cron)
-
- ☰ 4.2. The Linux Boot Process
- ☰ 4.2.1. BIOS vs UEFI
- ☰ 4.2.2. Understanding GRUB2
- ☰ 4.2.3. Kernel loading
- ☰ 4.2.4. initramfs
- ☰ 4.2.5. Troubleshooting boot issues
-
- ☰ 4.3. Kernel Management
- ☰ 4.3.1. What is the kernel?
- ☰ 4.3.2. Kernel modules
- ☰ 4.3.3. Kernel parameters
- ☰ 4.3.4. Compiling a custom kernel
- ☰ 4.3.5. Kernel versioning and updates
-
- ☰ 4.4. Advanced Filesystems and Storage
- ☰ 4.4.1. LVM concepts
- ☰ 4.4.2. Logical volumes
- ☰ 4.4.3. RAID levels
- ☰ 4.4.4. Full disk encryption (LUKS)
- ☰ 4.4.5. Snapshots and rollbacks
-
- ☰ 4.5. Network Services
- ☰ 4.5.1. SSH server configuration
- ☰ 4.5.2. NFS
- ☰ 4.5.3. Samba
- ☰ 4.5.4. FTP/SFTP
- ☰ 4.5.5. Firewalls in depth
-
- ☰ 4.6. Logging and Auditing
- ☰ 4.6.1. Systemd logging
- ☰ 4.6.2. Traditional logs in /var/log
- ☰ 4.6.3. Auditd
- ☰ 4.6.4. Log rotation
- ☰ 4.6.5. Creating custom logs
-
- ☰ 4.7. Virtualization and Containers
- ☰ 4.7.1. Virtual machines (KVM/QEMU)
- ☰ 4.7.2. Linux containers (LXC/LXD)
- ☰ 4.7.3. Docker fundamentals
- ☰ 4.7.4. Podman vs Docker
- ☰ 4.7.5. Container networking
-
-
- ☰ 5. PART V — Server Administration (Expert)
- ☰ 5.1. Web Servers
- ☰ 5.1.1. Apache basics
- ☰ 5.1.2. Nginx basics
- ☰ 5.1.3. Virtual hosts
- ☰ 5.1.4. SSL/HTTPS
- ☰ 5.1.5. Reverse proxy concepts
-
- ☰ 5.2. Database Servers
- ☰ 5.2.1. MySQL/MariaDB
- ☰ 5.2.2. PostgreSQL
- ☰ 5.2.3. Database backup strategies
- ☰ 5.2.4. Database hardening
-
- ☰ 5.3. Email Services
- ☰ 5.3.1. SMTP fundamentals
- ☰ 5.3.2. Configuring Postfix
- ☰ 5.3.3. IMAP/POP3 with Dovecot
- ☰ 5.3.4. Spam filtering systems
- ☰ 5.3.5. Email routing concepts
-
- ☰ 5.4. DNS and DHCP
- ☰ 5.4.1. Understanding DNS
- ☰ 5.4.2. Setting up BIND
- ☰ 5.4.3. DNS zones and records
- ☰ 5.4.4. DHCP server configuration
- ☰ 5.4.5. DNS troubleshooting
-
- ☰ 5.5. Load Balancing
- ☰ 5.5.1. HAProxy fundamentals
- ☰ 5.5.2. Nginx as a load balancer
- ☰ 5.5.3. Session persistence
- ☰ 5.5.4. High availability concepts
-
- ☰ 5.6. Clustering and High Availability
- ☰ 5.6.1. Failover principles
- ☰ 5.6.2. Pacemaker
- ☰ 5.6.3. Corosync
- ☰ 5.6.4. Cluster resource management
- ☰ 5.6.5. Distributed filesystems
-
-
- ☰ 6. PART VI — DevOps and Cloud
- ☰ 6.1. Linux for Developers
- ☰ 6.1.1. Compiler toolchains (gcc, make)
- ☰ 6.1.2. Git fundamentals
- ☰ 6.1.3. Debugging tools (gdb, strace)
- ☰ 6.1.4. Build automation (Makefile, CMake)
-
- ☰ 6.2. DevOps on Linux
- ☰ 6.2.1. CI/CD principles
- ☰ 6.2.2. YAML basics
- ☰ 6.2.3. GitHub Actions
- ☰ 6.2.4. GitLab CI/CD
- ☰ 6.2.5. Automated testing
-
- ☰ 6.3. Configuration Management
- ☰ 6.3.1. Ansible basics
- ☰ 6.3.2. Playbooks and inventories
- ☰ 6.3.3. Puppet overview
- ☰ 6.3.4. Chef overview
-
- ☰ 6.4. Infrastructure as Code
- ☰ 6.4.1. Terraform fundamentals
- ☰ 6.4.2. Providers and resources
- ☰ 6.4.3. Modules
- ☰ 6.4.4. Cloud provisioning with Terraform
-
- ☰ 6.5. Cloud Computing with Linux
- ☰ 6.5.1. Linux on AWS
- ☰ 6.5.2. Linux on Azure
- ☰ 6.5.3. Linux on GCP
- ☰ 6.5.4. Cloud networking basics
- ☰ 6.5.5. Scaling and monitoring
-
-
- ☰ 7. PART VII — Master Topics
- ☰ 7.1. Hardening a Linux System
- ☰ 7.1.1. Hardening principles
- ☰ 7.1.2. Kernel hardening
- ☰ 7.1.3. File integrity monitoring
- ☰ 7.1.4. Vulnerability scanning
-
- ☰ 7.2. Forensics and Incident Response
- ☰ 7.2.1. Collecting evidence
- ☰ 7.2.2. Log and file recovery
- ☰ 7.2.3. Analyzing suspicious processes
- ☰ 7.2.4. Incident response workflow
-
- ☰ 7.3. Performance Tuning
- ☰ 7.3.1. CPU tuning
- ☰ 7.3.2. Memory tuning
- ☰ 7.3.3. Disk and I/O optimization
- ☰ 7.3.4. Profiling tools
-
- ☰ 7.4. Writing Linux Tools
- ☰ 7.4.1. Bash-based tools
- ☰ 7.4.2. Python command-line tools
- ☰ 7.4.3. Writing tools in C
- ☰ 7.4.4. Using Linux system APIs
-
- ☰ 7.5. Linux Internals
- ☰ 7.5.1. Process lifecycle
- ☰ 7.5.2. Memory management
- ☰ 7.5.3. Signals and IPC
- ☰ 7.5.4. Namespaces
- ☰ 7.5.5. cgroups
-
- ☰ 7.6. Becoming a Linux Expert
- ☰ 7.6.1. Career paths
- ☰ 7.6.2. Certifications (RHCE, LFCS, LPIC)
- ☰ 7.6.3. Building a homelab
- ☰ 7.6.4. Contributing to open source
-
-
Comments
Please login to add a comment.
Don't have an account? Register now!