Delete files and folder using CronJob in Linux VPS

Linux Server Management Tips and Tricks
Post Reply
arnlweb
Site Admin
Posts: 92
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

Delete files and folder using CronJob in Linux VPS

Post by arnlweb » Wed Jan 04, 2017 10:36 am

Currently, I am using Vesta Cp.

# Make a cron job #

Create a cronfile: sudo /usr/local/vesta/bin/delete_video.sh

Code: Select all

chmod a+x /usr/local/vesta/bin/delete_video.sh
(0770)

delete_video.sh file:

Code: Select all

# Detele Dowloaded videos by time #
/usr/bin/find /home/admin/web/*/public_html/videos/* -maxdepth 0 -cmin +60 -exec rm -fr {} +

# Detele Edited files by time #
/usr/bin/find /home/admin/web/*/public_html/folder1/* -maxdepth 0 -cmin +60 -exec rm -fr {} +

# Detele Converted files and folder by time #
/usr/bin/find /home/admin/web/*/public_html/folder2/* -maxdepth 0 -cmin +60 -exec rm -fr {} +
Edit Cron Tab file:

Code: Select all

crontab -e


Then add this line

Code: Select all

* * * * * sudo /usr/local/vesta/bin/delete_video.sh
Also, you can add a cronjob using vesta admin panel.

You are done, this cron will delete 60 minutes older files and folder from the server.

Post Reply