Cron command to delete folder including all sub-folders and files

The following cron command line can be used to delete a folder including all sub-folders and files.

In this example we’ll be deleting a temporary upload folder – it is VERY important that you get the directory path correct – otherwise you might end up deleting the wrong folder. Backing up before setting up this command would be a good idea.

Assuming your web server has cPanel access, open up the ‘File Manager’ tool, browse to the folder and copy the path.

Replace bold text with YOUR directory path.

rm -rf public_html/demo.itsupportguides.com/wp-content/uploads

Once you have the command for your directory, open up the ‘Cron Jobs’ tool and add a new cron job specifying how often you want it to run – for example, once every ten minutes.