February 1, 20233 yr Just want to share this User Script to delete Files and Folders older than 64 Days (change my_days). I use it to delete old Surveillance Footage my IP-Cameras are transferring via FTP to my UNRAID Server. #!/bin/bash #name=Delete old surveillance recordings #description=Delete files older than x days and empty folders #arrayStarted=true # Days to keep my_days=64 # Folder to clean my_dir=/mnt/user/ipcam/ # Check if directory exist and quit if not if [ ! -d "$my_dir" ]; then echo ERROR: $my_dir does not exist exit 2 fi # Delete files older than x days find $my_dir/garten/* -type f -maxdepth 9999 -mtime +$my_days -delete # Delete empty folders find $my_dir/garten/* -type d -empty -delete find $my_dir/garten2/* -type f -maxdepth 9999 -mtime +$my_days -delete find $my_dir/garten2/* -type d -empty -delete find $my_dir/haustuer/* -type f -maxdepth 9999 -mtime +$my_days -delete find $my_dir/haustuer/* -type d -empty -delete echo Total Files: $(find $my_dir -type f | wc -l) echo Total Size: $(du -hs $my_dir | awk '{ print $1; }') exit 0 EDIT: find Documentation https://www.gnu.org/software/findutils/manual/html_mono/find.html Edited March 18, 20233 yr by pixeldoc81 Update
February 22, 20233 yr Would I be able to modify this to make it in terms of hours rather than days? Can I use a decimal? i.e. my_days=0.5?
March 18, 20233 yr Author @winwash54 The find command does only support fraction values of n*24 hours, but not hours. Look at the find Manual: https://www.gnu.org/software/findutils/manual/html_mono/find.html#Age-Ranges Edited March 18, 20233 yr by pixeldoc81
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.