I created the following script thinking it would look in the recycle bin and delete all files and folders that are older than 90 days.
#!/bin/sh
####################################
#
# simple script that will walk thru the
# recycle bins on NAS and delete everything
# older than 90 days
#
####################################
/usr/bin/find /share/HDA_DATA/"Network Recycle Bin"/*.* -mtime +90 -exec rm {} \;
when I run it ([/share/Data/templates] # ./cleanrecyclebin.sh) I get the following .....
BusyBox v1.01 (2012.12.04-18:29+0000) multi-call binary
Usage: find [PATH...] [EXPRESSION]
Search for files in a directory hierarchy. The default PATH is
the current directory; default EXPRESSION is '-print'
EXPRESSION may consist of:
-follow Dereference symbolic links.
-name PATTERN File name (leading directories removed) matches PATTERN.
-print Print (default and assumed).
-type X Filetype matches X (where X is one of: f,d,l,b,c,...)
-perm PERMS Permissions match any of (+NNN); all of (-NNN);
or exactly (NNN)
-mtime TIME Modified time is greater than (+N); less than (-N);
or exactly (N) days
[/share/Data/templates] #
Script that will delete files and folders older than 90 days
- mackconsult
- Know my way around
- Posts: 158
- Joined: Tue Oct 13, 2009 10:52 am
- Location: Vancouver, WA
- Contact:
Script that will delete files and folders older than 90 days
QNAP TS259
QNAP TS421
QNAP TS649
QNAP TS421
QNAP TS649
-
- Know my way around
- Posts: 185
- Joined: Tue Oct 30, 2012 12:12 am
Re: Script that will delete files and folders older than 90
There is already a setting for this on my nas in the gui
- pwilson
- Guru
- Posts: 22533
- Joined: Fri Mar 06, 2009 11:20 am
- Location: Victoria, BC, Canada (UTC-08:00)
Re: Script that will delete files and folders older than 90
Busybox v1.01 does NOT support the "-exec" parameter in it's "find" command.mackconsult wrote:I created the following script thinking it would look in the recycle bin and delete all files and folders that are older than 90 days.
Code: Select all
#!/bin/sh #################################### # # simple script that will walk thru the # recycle bins on NAS and delete everything # older than 90 days # #################################### /usr/bin/find /share/HDA_DATA/"Network Recycle Bin"/*.* -mtime +90 -exec rm {} \;
Solution:
- Install Optware IPKG (using the instructions in QNAPedia article: Install Optware IPKG)
- Install Optware version of "find":
Code: Select all
ipkg update ipkg install findutils
- Create your script:
Click on "SELECT ALL" (above this code segment), and then cut&paste it into an SSH session on your NAS
Code: Select all
cat >/opt/bin/cleanrecyclebin <<EOF #!/bin/sh #################################### # # simple script that will walk thru the # recycle bins on NAS and delete everything # older than 90 days # # Dependancies: This script requires Optware, # and "findutils" installed on NAS #################################### /opt/bin/find /share/HDA_DATA/"Network Recycle Bin"/*.* -mtime +90 -exec rm {} \; EOF chmod +x /opt/bin/cleanrecyclebin
- Run "/opt/bin/cleanrecyclebin" whenever you want to "purge" files over 90 days old in your recycling bin.
Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs
Please review: When you're asking a question, please include the following.
-
- Know my way around
- Posts: 103
- Joined: Wed Aug 13, 2008 1:39 am
Re: Script that will delete files and folders older than 90 days
I know this thread is very old but I recently needed a similar solution but had lots of trouble getting Optware or alike installed on an older QNAP NAS. I eventually found this command which did the trick without any special packages.
In my case I did not have a time requirement. Just wanted to remove all files that matched a certain filename pattern.
The key to getting a solution without Optware or alike was piping it to the while loop that took each line that the find command returned and executed the desired code on it. In this case the rm command.
Probably inefficient and may need tweaking, but it worked when nothing else would.
In my case I did not have a time requirement. Just wanted to remove all files that matched a certain filename pattern.
Code: Select all
find . -type f -name <search criteria here> -print | while read LINE; do rm "$LINE" ; done
Probably inefficient and may need tweaking, but it worked when nothing else would.