How to empty all cPanel File Manager .trash bins
When deleting files using cPanel's file manager the default option is to move the files into the trash bin. There is an option to skip sending the file to the trash can but many don't see this option or they move data into the trash and forget it's there. This can consume valuable disk space and if you have backup's enabled, the backups will be larger and take longer to complete.
The following script was created to clean out these trash bins when when files have existed in them for more than 30 days
#!/bin/bash getent=$(getent passwd) if [ $? -ne 0 ]; then echo "getent passwd command failed" exit 1 fi getent passwd | while IFS=: read -r user_name user_pw user_id user_gid user_comments user_homedir user_shell; do if [ ${user_id} -lt 500 ]; then echo "$user_name has a id (${user_id}) less then 500, skipping this user" continue fi if [ ! -d "${user_homedir}/.trash" ]; then echo "${user_name} does not have a ${user_homedir}/.trash folder, skipping this user" continue fi echo "Cleaning ${user_homedir}/.trash" su ${user_name} -s /bin/bash -c 'find ~/.trash/ -mtime +30 -type f -exec rm -vf {} \;' su ${user_name} -s /bin/bash -c 'find ~/.trash/ -mtime +30 -type d -empty -delete' echo "Done Cleaning ${user_homedir}/.trash" done