Deleting files and directory's older than 3 months

I have a qnap TS259 that is running ubuntu. Have successfully setup back scripts that are initiated by cron.

I would like to create a couple scrypts that would operate on the recycle bins for both drives. Just want to be able to run the script manually that would walk through both directories and delete everything that is older than 3 months or 90 days. Any help or indications on were to look would be great.

Regards,

Read the man page of find

$man find

Especially the part about -printf

and this option

%Ak    File's last access time in the  format  specified  by  k,
                     which  is  either `@' or a directive for the C `strftime'
                     function.  The possible values for k  are  listed  below;
                     some  of  them might not be available on all systems, due
                     to differences in `strftime' between systems.

If you continue reading from this part, can find the K param

Well I tried the following:

#!/bin/sh
####################################
#
# simple script that will walk thru the
# recycle bins on NAS and delete everything
# older than 90 days
#
####################################

find /share/HDA_DATA/Network Recycle Bin/*.* -mtime +90 -exec rm {} \;

When I try and execute it though I get the following in putty:

[/share/Data/templates] # ./cleanrecyclebin.sh
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] # ./cleanrecyclebin.sh
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] #
[/share/Data/templates] # [/share/Data/templates] # ./cleanrecyclebin.sh
-sh: [/share/Data/templates]: No such file or directory
y/share/Data/templates] # BusyBox v1.01 (2012.12.04-18:29+0000) multi-call binar
-sh: syntax error near unexpected token `('
[/share/Data/templates] #

[/share/Data/templates] # Usage: find [PATH...] [EXPRESSION]
-sh: Usage:: command not found
[/share/Data/templates] #
t PATH isata/templates] # Search for files in a directory hierarchy.  The defaul
-sh: Search: command not found
[/share/Data/templates] # the current directory; default EXPRESSION is '-print'
-sh: the: command not found
-sh: default: command not found
[/share/Data/templates] #
[/share/Data/templates] # EXPRESSION may consist of:
-sh: EXPRESSION: command not found
[/share/Data/templates] #         -follow         Dereference symbolic links.
-sh: -follow: command not found
 removed) matches PATTERN.        -name PATTERN   File name (leading directories
-sh: syntax error near unexpected token `('
[/share/Data/templates] #         -print          Print (default and assumed).
-sh: syntax error near unexpected token `('
[/share/Data/templates] #
 one of: f,d,l,b,c,...) #         -type X         Filetype matches X (where X is
-sh: syntax error near unexpected token `('
); all of (-NNN);lates] #         -perm PERMS     Permissions match any of (+NNN
-sh: syntax error near unexpected token `('
[/share/Data/templates] #                         or exactly (NNN)
-sh: syntax error near unexpected token `('
(+N); less than (-N);s] #         -mtime TIME     Modified time is greater than
-sh: syntax error near unexpected token `('
[/share/Data/templates] #                         or exactly (N) days
-sh: syntax error near unexpected token `('
[/share/Data/templates] #
[/share/Data/templates] #

The problem is because you have directory name with blank spaces. Wrap the path in single quotes and re-try:-

find '/share/HDA_DATA/Network Recycle Bin/'*.* -mtime +90 -exec rm {} \;

Hmmmm still not working ....

[/share/Data/templates] # ./cleanrecyclebin.sh
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] #

Put this line before the find command in your script and try:-

export PATH=/opt/bin:/opt/sbin:$PATH

Still not seams to be working ......

[/share/Data/templates] # ./cleanrecyclebin.sh
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



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] #

Issue is that it is using the BusyBox command. You have to identify the absolute path of find command and use it in your script to resolve this issue. I hope this helps.

Okay I have been poking around in my QNAP which doesn't have man pages enabled. What might be the path to find or is there a command I can use to find it.

You can look in following directories:-

/bin/
/usr/bin/
/sbin/
/opt/bin/
/opt/sbin/

Still not working????

#!/bin/sh
####################################
#
# simple script that will walk thru the
# recycle bins on NAS and delete everything
# older than 90 days
#
####################################

export PATH=/opt/bin:/opt/sbin:$PATH
/usr/bin/find /share/HDA_DATA/"Network Recycle Bin"/*.* -mtime +90 -exec rm {} \;

You can remove that export if you are using absolute path.

BTW what issues are you facing this time? Can you post the error message if any?

[/share/Data/templates] # ./cleanrecyclebin.sh
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] #

Ok, you are using the BusyBox find command and the manual which you posted above cleary shows that it does not support -exec option that you are using.

You are supposed to use only the options shown in the manual.

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