CronJob - delete files and folder

Good morning to all:)

Trying to sort an Cron job thatdeletes all files and folders from specific folder older then 30 days with command “find /mnt/Pool/FTP/* -mtime +30 -exec rm -rf {} ;” but this deleted all files and folders in the path.

Could someone help what im doing wrong ??

mtime updates are not done recursively. You really want to delete only files, not folders recursively. You can have a separate run which removes empty folder.

Can You please specify how can i do it as if i understand then i need to create 2 separate cronjobs ?

Looking those thread here and there, i think that using -exec rm -rf {} ; can lead to problems.

If i may suggest, in your place would first check for files find /mnt/Pool/FTP -type f -mtime +30 -delete (test it before lauch destructive command, just swap -delete with -print), then for empty folders with find /mnt/Pool/FTP -empty -type d -delete

1 Like

Thank you

Will give it a try and conmfim
Have a nice day :slight_smile:

Please keep in mind that clients can change modification time of files. Make sure your ftp clients don’t try to preserve file modification timestamp.

Thanks for idea good point :slight_smile:

For my purpose this will be enough as only camera logs into FTP when alarm triggers :slight_smile: