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

Danny Stieben 04-02-2013

clam antivirusThere are a few ways in which you can access Clam Antivirus for numerous purposes, such as removing viruses from Windows systems Kill Windows Viruses With an Ubuntu Live CD Today's anti-virus solutions are pretty reliable, protecting you from most of the common threats out there in the world. With safe browsing habits, there's a rare chance that you'd ever get infected with malware. However,... Read More . 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 Scan Your System And Removable Media For Viruses With ClamTk [Linux] ClamAV may be even more popular on Linux, where it first began its life. In this article, we'll be taking a look at the most popular client of ClamAV for Linux, known as ClamTk. ClamTk... Read More 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.


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 antivirus

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 antivirus

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.



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!

Related topics: Anti-Malware, Computer Maintenance.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. SaapeXD MoHods
    March 6, 2013 at 6:54 am

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

    • Ibnuhusein
      June 25, 2013 at 12:06 pm

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

  2. Jan Hovancik
    February 7, 2013 at 5:22 am

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

    • Danny Stieben
      February 28, 2013 at 9:06 pm

      I'm quite happy with using ClamTK.

  3. Samyak Puri
    February 5, 2013 at 7:18 pm

    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

  4. Siosilvar
    February 5, 2013 at 3:25 am

    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.

    • Danny Stieben
      February 28, 2013 at 9:05 pm

      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.

  5. dragonmouth
    February 4, 2013 at 9:55 pm

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

    • Jan Hovancik
      February 7, 2013 at 8:34 am

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

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

    • Danny Stieben
      February 28, 2013 at 9:03 pm

      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.

      • prasad
        January 15, 2019 at 2:24 pm


        I have a quick question on clamAV?

        1)how can I scan on Demand?(example scan 1am in the morning)

      • prasad
        January 15, 2019 at 2:37 pm

        I have installed clamAV on ubuntu 16.04, please let me know how can I schedule a virus scan using ClamAV?