When users delete files, they may continue to take space until removed from the Recycle Bin. This article will walk through how to create a maintenance item that will remove all items in the bin that are older than a certain amount of days.
Script
First, you will need to build out the script the maintenance item will run. Only modify the days variable on line 3 to set how old the files you'd like deleted to be:
#!/bin/bash
days="20"
oldIFS="$IFS"
IFS=$'\n'
Users=$(dscl . list /Users | grep -v '_')
for User in $Users
do
Trash="/Users/$User/.Trash"
if [ -e "$Trash" ]; then
Files=$(ls "$Trash") &> /dev/null
if [[ $Files == "" ]]; then
echo "no files"
fi
epochToday=$(date +%s)
for f in $Files
do
fileEpoch=$(date -r "$Trash/$f" +%s)
epochDifference=$((epochToday - fileEpoch))
daysSince=$((epochDifference / (60 * 60 * 24)))
if [[ $daysSince -gt $days ]]; then
rm -rf "$Trash/$f"
echo "$Trash/$f"
fi
done
fi
done
Maintenance Item
After building this script out you can setup the Maintenance item to deploy this to your devices. Here is what the final product will look like: