Automatically Empty the CIFS/SMB Recycle bin On A FreeNAS or XigmaNAS Server.

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


If you are using XigmaNAS or FreeNAS then you would be feeling tired cleaning .recycle folder every certain days. Here I will explain the automatic removal script that will help you to be stressful for such task and Yes you can set it as you want to.. Accordingly.

Firstly, If you want to enable the recycle bin then you can do it from (Services -> CIFS/SMB -> Shares) and then edit the share you have already created from the above option you will see then checkbox for “Enable recycle bin”.

Now, time to create sh file. We will do it step by step as below:

First we will see how we can create sh file using web interface then after we will see how we can create sh using terminal.

First step:

How to create sh file in XigmaNAS using web interface?

Login with your admin user in web interface of XigmaNAS.

Go to Tools -> command

In the box, type:

mkdir /root/autorecycledel

Hit the Execute button, then type:

touch /root/autorecycledel/autorecycledel.sh

Hitting the Execute button to finish.

Next, go to Tools-> File Editor
For the path, either type:

/root/autorecycledel/autorecycledel.sh

then click the execute.
Copy and paste the following into the blank box:

#!/bin/sh
find /mnt/movie/.recycle/* -atime +10 -exec rm -rf '{}' \;
find /mnt/movie/.recycle/ -depth -type d -empty -exec rmdir {} \;

Note: the /mnt/movie/.recycle is the path to my recycle bin. You will need to change this to reflect your recycle bin path accordingly.

Understand, the “+10”. That’s how old a file has to be before it deletes it from the recycle bin. If you want 15 days, change it to +15. If you want 45 days, change it to +45

Finally, go to: System -> Advanced -> Cron and create a new cron job, setting the following:
Command: sh /root/autorecycledel/autorecycledel.sh
Who: root
Description: Empty recycle bin of files older than 10 days
Schedule time:
– Minutes: Selected | 0
– Hours: Selected | 0
– Days: All
– Months: All
– Week days: All

The scheduled time can be set for whenever you wish the cron job to happen… As shown above, I have set it for Midnight every day.

Save it and you’re done!

If you want to manually run the cron job, edit the job and click the “Run Now” button.

This is also another way of testing to make sure everything is setup right, otherwise you will get a “Cron Job Failed to Execute” error.

Second step:

How to create sh file in XigmaNAS using command line ?

Login in your XigmaNAS server using terminal (If you are using linux at client side) or putty (If you are using windows at client side).

Using terminal run below command:

$ssh [email protected]

Here 192.168.1.100 is my XigmaNAS server’s IP.

Now create directory file.

$ mkdir /root/autorecycledel

Create sh file with below command:

$ touch /root/autorecycledel/autorecycledel.sh

Now open file in vi editor or nano editor.

$ nano autorecycledel.sh

And copy below content to the sh file:

#!/bin/sh
find /mnt/movie/.recycle/* -atime +10 -exec rm -rf '{}' \;
find /mnt/movie/.recycle/ -depth -type d -empty -exec rmdir {} \;

Note: the /mnt/movie/.recycle is the path to my recycle bin. You will need to change this to reflect your recycle bin path accordingly.

Understand, the “+10”. That’s how old a file has to be before it deletes it from the recycle bin. If you want 15 days, change it to +15. If you want 45 days, change it to +45

If you have more than one shared folder than you have to extend the above script. For example if you have 3 folders. Movie, Music and Picture then the script should be like below:

#!/bin/sh

find /mnt/movie/.recycle/* -atime +10 -exec rm -rf '{}' \;
find /mnt/movie/.recycle/ -depth -type d -empty -exec rmdir {} \;
find /mnt/music/.recycle/* -atime +10 -exec rm -rf '{}' \;
find /mnt/music/.recycle/ -depth -type d -empty -exec rmdir {} \;
find /mnt/picture/.recycle/* -atime +10 -exec rm -rf '{}' \;
find /mnt/picture/.recycle/ -depth -type d -empty -exec rmdir {} \;

Now open the cronjob editor:

$crontab –e

Then copy below command:

0 0 * * * sh /root/autorecycledel/autorecycledel.sh

Note: The scheduled time can be set for whenever you wish the cron job to happen… As shown above, I have set it for Midnight every day


This article is contributed by RootLinuxBlog. If you like RootLinuxBlog and would like to contribute, you can submit an article using contact us from. See your article appearing on the RootLinuxBlog main page and help other Techies.
Please write comments if you found any error with the above article would really help us to serve you a better way. Thank you…

Please follow and like us:
Empty the folder automatically after certain days. (FreeNAS & XigmaNAS)
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)

Facebook106
Facebook
LINKEDIN98