Scanning with ClamAV¶
In this article
ClamAV is a free, cross‑platform, open‑source antivirus designed to detect trojans, viruses, malware, and other threats. It is most commonly used on servers and mail gateways.
Installation¶
Ubuntu / Debian¶
Note
The clamav-daemon package (the clamd daemon) is only needed for background scanning via clamdscan or for integration with other services (for example, a mail server). For one-off scans with clamscan, the clamav package is sufficient.
CentOS / AlmaLinux / Rocky Linux¶
ClamAV packages are located in the EPEL repository.
For CentOS 7:
For AlmaLinux / Rocky Linux 8–10, CentOS 8 Stream (using dnf):
If you need the clamd daemon, additionally install the clamd package (sudo dnf install -y clamd). On RPM-based distributions, the daemon service is called clamd@scan, and its configuration is located in /etc/clamd.d/scan.conf.
Note
On systems with systemd (all modern distributions), the clamav-freshclam service manages automatic database updates. You can enable it with sudo systemctl enable --now clamav-freshclam.
Updating Signatures¶
Before first use, be sure to update the virus signature databases.
Standard method (when freshclam is running)¶
If you encounter an error ERROR: Can't open /var/lib/clamav/main.cvd: Permission denied or ERROR: Database lock file exists, the clamav-freshclam service may already be running and blocking the update. In that case, use:
Resource Requirements¶
- RAM: For full scans, at least 1–1.5 GB of free RAM is recommended.
- Swap: If no swap partition or file exists, set it up, especially on VPS with limited memory. The procedure is described in the article Managing swap: creation and resizing.
Scanning Examples¶
| Task | Command |
|---|---|
| Scan a single file | clamscan /path/to/file |
| Recursive folder scan (infected only) | clamscan -r -i /folder |
| Move infected files | clamscan -r --move=/quarantine /folder |
| Automatically delete infected files | clamscan -r --remove /folder |
| Output report to file | clamscan -r -i /folder > scan_report.txt |
Use the clamd daemon (faster on repeated scans) | clamdscan /folder |
Note
The --remove option permanently deletes files. Use it only after testing and with a backup.
To speed up repeated scans, it is recommended to use clamdscan (runs via the clamd daemon), after starting the service:
sudo systemctl start clamav-daemon # Ubuntu / Debian
sudo systemctl start clamd@scan # CentOS / AlmaLinux / Rocky Linux
sudo clamdscan /folder
clamdscan scans directories recursively by default. Note that the daemon runs as a separate user and must have read access to the files being scanned (or use the --fdpass option).
Useful Tips¶
- To check if
clamdis running: - Scanning logs (by default) are located in
/var/log/clamav/. - To schedule regular scans, set up
cron: