How to empty smba/cifs .recycle

Status
Not open for further replies.

Guntis

Cadet
Joined
May 18, 2016
Messages
4
I found this:
Code:
find /mnt/*/.Trashes/ -type f -mtime +5d -delete
find /mnt/*/.Trashes/ -type d -empty -depth -delete

find /mnt/*/.Trashes/ -type f -mtime +5d -exec rm -fv {} \;
find /mnt/*/.Trashes/ -type d \! -path "*/" -empty -depth -exec rm -frv {} \;


here: https://forums.freebsd.org/threads/44848/

I think this will work for all shares if I modify it like this

Code:
find /mnt/<pool_name>/*/.recycle/ -type f -mtime +5d -delete
find /mnt/<pool_name>/*/.recycle/ -type d -empty -depth -delete

find /mnt/<pool_name>/*/.recycle/ -type f -mtime +5d -exec rm -fv {} \;
find /mnt/<pool_name>/*/.recycle/ -type d \! -path "*/" -empty -depth -exec rm -frv {} \;


there is also this:
Code:
#!/bin/bash

###
#  meant to cleaup deleted/recycled files & folders
#  they will have been kept for a while, probably 7 days
#  then cleared out with this script, run from cron/anacron
###

# Create Temp Log File
RUNON=$(date +"%F__%R")
TMPLOGFILE=$(mktemp "houseCleaning_$RUNON.XXXXXXXXX" --tmpdir=$TMPDIR)
LOGDIR=/var/log
LOGFILE=$LOGDIR/houseCleaning.log

# Find and Log files older than 7 days old
echo "finding files deleted more than 7 days ago" >> $TMPLOGFILE
find /mnt/vol0/*/.recycle/* -type f -mtime +7 >> $TMPLOGFILE
# Delete files older than 7 days
find /mnt/vol0/*/.recycle/* -type f -mtime +7 -delete

# Find and Log empty directories
echo "finding empty directories" >> $TMPLOGFILE
find /mnt/vol0/*/.recycle/* -type d -empty >> $TMPLOGFILE
# Delete empty directories
find /mnt/vol0/*/.recycle/* -type d -empty -delete

# Find and Log empty files
echo "finding empty files" >> $TMPLOGFILE
find /mnt/vol0/*/.recycle/* -type f -empty >> $TMPLOGFILE
# Delete empty files
find /mnt/vol0/*/.recycle/* -type f -empty -delete

# Update Log File
echo "Script:  $0" >> $LOGFILE
echo "Executed: $RUNON" >> $LOGFILE
cat $TMPLOGFILE >> $LOGFILE
echo "------------------" >> $LOGFILE

that is written for Ubuntu, but in comments they say that it works for freenas too.

I will report back if this works.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
You know we have a "how to" on this exact issue. I know because I wrote it. In fact, that first set of code you provided looks exactly like what I wrote. ;)
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Nope, but that one will work too. Mine actively searches out .recycle directories and then deletes old stuff.
 

Guntis

Cadet
Joined
May 18, 2016
Messages
4
it's probably just me, but i can't find it. Can you please post link here?
 
Status
Not open for further replies.
Top