brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: clamscan -r -i scans a folder and prints only the infected files

Linux
~/tips/tip-security-clamscan-recursive-infected-only

clamscan -r -i /mnt/user/share

Scans a folder recursively with ClamAV and lists only the infected files.

I do not run antivirus on my Linux servers all day, but a share that other people write to is a different story. ClamAV’s command-line scanner covers it in one line.

clamscan scans the files and folders you give it. Two options make a folder scan useful. -r scans subdirectories recursively, and -i prints only the infected files, so clean ones do not fill the screen.

clamscan -r -i /mnt/user/share

Replace the path with the folder you want to check, for example a share where downloads or uploads land. The scan ends with a summary.

To skip folders that make no sense to scan, such as a cache, use --exclude-dir with a regular expression. You can repeat the option.

clamscan -r -i --exclude-dir="^/mnt/user/share/cache" /mnt/user/share

Two more options act on what is found, --remove and --move=DIRECTORY. Warning: the man page says “Be careful!” about --remove, and a false positive would delete a real file. I would start without it. --move into a quarantine folder is gentler, and that folder must be writable by the user who runs the scan.

The scanner is only as current as its virus database. The man page points to freshclam for updates, so see the ClamAV documentation for how your install gets them. A clean result also means only that nothing known was found.

Further reading: clamscan man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link