Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

User Script: Delete Files older than x Days and Empty Folder

Featured Replies

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 by pixeldoc81
Update

  • 3 weeks later...

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?

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.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.