Automating LiteSpeed Cache Cleanup with a cPanel Cron Job

The Guardian of the Cache: Automating Your Website’s LiteSpeed Cache Clearing

When your LiteSpeed Cache directory grows past 1 GB, it starts eating into your hosting disk quota. Use this safe daily cPanel Cron Job to prune stale cache files automatically.

Automate Your LiteSpeed Cache
Cleanup in cPanel

LiteSpeed Cache keeps WordPress fast, but once your lscache folder grows past 1 GB, it starts burning through disk space. A simple daily cPanel Cron Job cleans out stale cache files automatically at midnight.

Step-by-Step in cPanel

Set up the daily LiteSpeed Cache cleanup

This takes about five minutes in cPanel and runs automatically every night while traffic is lowest.

Step 1: Open Cron Jobs

Log in to your cPanel account, scroll to the Advanced section, and click Cron Jobs.

Step 2: Set the schedule

Under Add New Cron Job, open the Common Settings dropdown and choose Once Per Day (Minute: 0, Hour: 0). That runs the check at midnight server time.

Step 3: Paste the command

Paste the command below into the Command field, replacing both instances of yourusername with your actual cPanel username:

LARGE_LSDIR="$(du --threshold=1G -sh /home/yourusername/lscache/ | cut -f2-)"; for ls_path in $LARGE_LSDIR; do echo "$(date): Clean up $ls_path"; find "$ls_path" -type f -mmin +1440 -exec rm -f {} \;; done >> /home/yourusername/cron_log.txt 2>&1
Step 4: Save the job

Click Add New Cron Job to activate it. From now on, cPanel checks the folder size every night automatically.

What this command actually does: First, du --threshold=1G checks whether /home/yourusername/lscache/ is larger than 1 GB. If it is under 1 GB, nothing gets touched. If it exceeds 1 GB, find ... -mmin +1440 removes only cached files older than 1,440 minutes (24 hours) and appends a timestamped line to /home/yourusername/cron_log.txt.

Verification

How to test your cron job safely

Don’t wait until tomorrow morning to find out whether you had a typo in your username or path.

  • Temporarily set the schedule to run every 5 minutes (or a few minutes from now) and lower --threshold=1G to --threshold=200M (200 MB) so it triggers on a smaller cache folder.
  • Wait for the scheduled minute to pass, then open /home/yourusername/cron_log.txt in cPanel’s File Manager to verify a clean timestamped entry with no permission or path errors.
  • Once confirmed, edit the cron job back to Once Per Day (0 0 * * *) and restore --threshold=1G.

Watch the unit suffix: Always include M or G on --threshold (for example, --threshold=200M or --threshold=1G). Leaving off the letter makes du read the number as bytes instead of megabytes.

FAQ

Common questions

Will deleting old files in lscache break my WordPress website?

No. LiteSpeed Cache regenerates fresh cached pages automatically as visitors browse your site. Your WordPress database, themes, plugins, and media uploads are never touched.

Why did my lscache folder grow past 1 GB in the first place?

Busy blogs, WooCommerce stores, and pages with lots of query strings can create thousands of separate cache files over time. A daily size-checked cron job keeps storage flat without hurting cache hit rates on active pages.

Does this also help when I update old SEO articles?

Yes. Keeping your LiteSpeed cache clean ensures visitors and search crawlers see your latest edits promptly whenever you refresh cornerstone WordPress content.

Want TVCNet to Set This Up For You?

If you host with TVCNet and want our team to configure and test your LiteSpeed Cache cleanup cron job, open a quick ticket and we’ll take care of it.

Contact TVCNet Support →

Similar Posts

Leave a Reply