This script is a robust shell utility designed to scan directories for viruses using the open-source ClamAV engine. It combines automated updates, safe scanning, clear log reporting, and offers both command-line and graphical dialogs via Zenity for an optimal user experience.
- Antivirus scan with ClamAV (
clamscan) - Automatic update of virus definitions before every scan (
freshclam) - Graphical dialogs for selection and notifications (Zenity)
- Safe logging: scan results saved with timestamp
- Dependency check: verifies required software is installed
- User-friendly interface: color-coded output and clear prompts
- Error handling: manages edge cases and interruptions
- Git integration: detects if target directory is a Git repo and shows last commit info
- Linux (tested on Ubuntu, Debian, Arch, etc.)
- ClamAV (
clamav,clamav-daemon) - Zenity (
zenity) - Notify-send (
libnotify-bin) - Bash (scripted for bash usage)
- Clone or download the script file (
clamav.sh). - Ensure dependencies:
sudo apt install clamav clamav-daemon zenity libnotify-bin
- Make the script executable:
chmod +x clamav.sh
./clamav.sh- Database update: You may be prompted for
sudopassword to update virus definitions. - Directory selection: Choose the folder you want to scan via a file picker.
- Notifications: Desktop notifications follow each step.
- Log file: The scan report is saved in a timestamped
.logfile. - View details: Option to see log/report at the end of the scan.
If Zenity is not installed, the script falls back to text prompts.
- print_status: Shows colored status messages ([INFO], [WARN], [ERROR], [SUCCESS])
- print_progress: Displays a dynamic progress bar that fills the terminal line
- check_dependencies: Ensures that all required tools are present
- update_clamav_db: Updates virus definitions before scanning
- select_scan_directory: Chooses the target folder graphically or via text input
- perform_scan: Executes ClamAV scan, logs results, and summarizes findings
- print_git_info: Displays last git commit if the scanned folder is a repository
- Scan log: A file
clamav_scan_YYYYMMDD_HHMMSS.logis created in the working directory - Notifications: Desktop popups for key steps (requires notification system)
- Exit codes: Script uses meaningful exit codes for automation and troubleshooting
- Scan options: Edit the
clamscancommand in the script for deeper scan settings - Integration: Easily embedded in cron jobs or CI/CD (check exit codes for infection status)
- Sudo policy: Script enforces non-root usage except for freshclam database update
- Missing dependencies: The script will list missing commands and show install tips before exit
- Zenity warnings: GTK/Adwaita warnings can be resolved by cleaning your
~/.config/gtk-4.0/settings.ini - Permission issues: Run as normal user, enter
sudoworking password only when prompted for database updates
./clamav.sh
# Select folder -> Wait for scan -> View report > If infected files, take appropriate action!This script makes Linux file scanning with ClamAV simple, elegant and transparent for power users and non-technical users alike.
