Control Virus Scans From The Command Line With Clam Antivirus [Linux]

clamav logo   Control Virus Scans From The Command Line With Clam Antivirus [Linux]There are a few ways in which you can access Clam Antivirus for numerous purposes, such as removing viruses from Windows systems. First, there’s a front end to Clam Antivirus which you can use to perform tasks graphically. It is called Clamtk and has been featured on MakeUseOf before. By installing the graphical front end, your package manager should also pull in the Clam Antivirus engine that it depends on.

The other option is to skip the graphical interface and just use the Clam engine via the command line. Running the engine via the command line may be advantageous for a number of reasons, such as when issuing commands to another machine via SSH, or when you’re working on a weak system that lags under a graphical desktop environment. This is also good for servers, because they will most likely want to run antivirus scans to prevent the spread of viruses to whichever clients connect to the server.

Installation

Before you begin, it’d be best to go ahead and install the Clam antivirus engine. You can search through your respective package manager for “clam antivirus“, and then install the main package. All other dependencies should be pulled in automatically.

You can also run sudo apt-get install clamav clamav-freshclam if you’re running Ubuntu, or sudo yum install clamav clamav-updates if you’re running Fedora. As Clam is very lightweight as far as antivirus solutions go, it shouldn’t take very long at all to download and install the packages.

Updating Virus Definitions

clam linux freshclam   Control Virus Scans From The Command Line With Clam Antivirus [Linux]

The first thing you’ll want to do after installing is update the virus definitions to be able to detect the latest threats. This can be easily accomplished by running the command sudo freshclam. It will instantly contact the Clam servers and download the latest definitions. The initial download will take a while as the definitions are newly downloaded.

Later updates should go a lot faster because freshclam will only download updates and not all definitions.

Sample Commands

clam linux scan   Control Virus Scans From The Command Line With Clam Antivirus [Linux]

Once the virus definitions have been updated, you can start a scan with the clamscan command. Running clamscan --help in the terminal will spit out a lot of different options which you can use to customize how Clam scans your files. However, if you want to keep it rather simple, you can recursively scan the folder “user” within the home folder by running the command clamscan -r /home/user. The recursive flag “-r” is important because otherwise Clam would simply scan any files within the user folder, but nothing that’s inside a folder inside the user folder.

Of course, if you need to scan a different directory, you can adjust the path appropriately. If you have any other specific needs, do check out what clamscan --help outputs as everyone’s needs vary if they need anything else besides a simple recursive scan.

Conclusion

While Linux desktop users probably won’t have to worry about viruses or scanners, power users or those running servers will definitely like having this option to protect both the system as well as any connecting clients from malicious code. As Clam Antivirus is open source and free, it’s easy for anyone to use and install. No matter what your needs are, consider trying Clam Antivirus for any virus scanning and removal tasks.

Do you ever need to scan for viruses with Linux? What do you think about Clam Antivirus? Let us know in the comments!

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

10 Comments -

0 votes

dragonmouth

I know that on Windows an anti-virus is a requirement but:
In your experience, how critical is running an anti-virus on Linux?

0 votes

Jan Hovancik

Are you running some mail-server? Or normal desktop?

If you have desktop, you do not need antivirus for your linux distribution.

0 votes

Danny Stieben

Anti-virus technically isn’t a requirement for Windows, either. You just have to strictly follow security practices and safe browsing. Windows is a lot more prone to viruses, however, so having it as a backup solution is a very good idea.

Unless you are running a server which handles a lot of different files (such as emails), then an anti-virus program is not needed at all, as none of the Windows-oriented malicious code can affect Linux. And the only reason why you should have an anti-virus program on a server is to prevent the spread of viruses to any client computer that connect to it, and not to protect the server from them. The server will be just fine.

0 votes

Siosilvar

If you have some need to use antivirus on Linux, why not use one that works? AVG is free for Linux and has better detection rates (about 84% vs. 76%). I suppose ClamAV has gotten better, but the only reason I can see to use it over AVG is for a GUI or for sticking strictly to Open Source Software.

0 votes

Danny Stieben

That’s true, although I’m not sure how active AVG is on the Linux front. I requested a key a long time ago, and I’m not sure if it ever arrived. Technically avast is another option, but it hasn’t been updated in a long time, so now it has issues ever since certain changes were introduced to the kernel.

0 votes

Samyak Puri

most virus are made keeping in mind that maximum users in the world use use windows o.s. But still there are some virus which are made for other operating systems. Also even if is not for linux it can be transferred to windows through a pendrive used in the linux containing the virus

0 votes

Jan Hovancik

i have it, just in case i need for some pendrive or so… but i use clamtk gui

0 votes

Danny Stieben

I’m quite happy with using ClamTK.

0 votes

SaapeXD MoHods

I dont use any Antivirus on Linux! :3 IS it bad?

0 votes

Ibnuhusein

No, that not bad, if you use normal desktop, you can to not use antivirus for your linux, you can safe.