I have installed clamav and cpulimit. I want to clamscan all directories in /home which are not owned by root 1 by 1 with a cpu limit of 70%.

I use the below command to do that in centos and almalinux:

find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root -exec cpulimit -l 70 -- /usr/bin/clamscan -i -r {} ; > /root/scan_results.txt

The above command works fine in centos. But in ubuntu 18 and 20, it creates multiple clamscan processes for each directory which are in /home and all the processes consume 70% cpu usage thereby overloading my server. I checked that using 'top' command. 'ps aux | grep clamscan' command also shows multiple clamscan processes running simultaneously.

find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root -exec /usr/bin/clamscan -i -r {} ; > /root/scan_results.txt

When I remove cpulimit from the command like shown above, it scans 1 by 1 but clamscan process consumes 100% cpu usage which I dont want.

I tried some other commands which didnt work as well:

  1. find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root | xargs -I {} cpulimit -l 70 -- /usr/bin/clamscan -i -r {} > /root/scan_results.txt
  2. find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root | xargs -P 1 -I {} cpulimit -l 70 -- /usr/bin/clamscan -i -r {} > /root/scan_results.txt

I want a command which scans all the /home directories which are not owned by root one at a time with cpulimit of 50% and not simultaneously.

1 Answer 1


It should work the same on both systems. On the centos system could you check how many directories in /home are owned by root? Only one or a low number of small directories that would scan quickly is only way I can think of to explain it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .