I'm trying to make a script that finds DIRECTORIES that are older than X days and delete them. So far, I am successful doing so if I'm trying to delete FILES. But I need it to include directories.
This is what I have:
#!/bin/sh
find /tmp/mnt/sdb1/Left/Archive/ -mtime +15 -exec rm -rf {} \;
find /tmp/mnt/sdb1/Right/Archive/ -mtime +15 -exec rm -rf {} \;
I don't believe this will include the directories inside the Archive directory. Adding -type d does not work; -type is not a valid switch here. It seems to be valid in DDWRT but not in Merlin.
Here's a quick test:
RT-N66U:/jffs/scripts# find /tmp/mnt/sdb1/Left/ -type d -mtime +15 -exec ls -lh {} \;
find: unrecognized: -type
BusyBox v1.20.2 (2015-01-09 00:44:43 EST) multi-call binary.
Usage: find [PATH]... [OPTIONS] [ACTIONS]
Search for files and perform actions on them.
First failed action stops processing of current file.
Defaults: PATH is current directory, action is '-print'
-follow Follow symlinks
Actions:
! ACT Invert ACT's success/failure
ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2
ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2
Note: -a has higher priority than -o
-name PATTERN Match file name (w/o directory name) to PATTERN
-iname PATTERN Case insensitive -name
-mtime DAYS mtime is greater than (+N), less than (-N),
or exactly N days in the past
If none of the following actions is specified, -print is assumed
-print Print file name
-print0 Print file name, NUL terminated
-exec CMD ARG ; Run CMD with all instances of {} replaced by
file name. Fails if CMD exits with nonzero
There is a directory in there:
RT-N66U:/tmp/mnt/sdb1/Left# ls -lh |grep -i archive
drwxrwxrwx 2 Admin root 704.0K Feb 24 01:00 Archive
+++
Any other suggestions as how I can accomplish this? I don't mind if it blows out all the files AND directories. I just need the directories gone.
This is what I have:
#!/bin/sh
find /tmp/mnt/sdb1/Left/Archive/ -mtime +15 -exec rm -rf {} \;
find /tmp/mnt/sdb1/Right/Archive/ -mtime +15 -exec rm -rf {} \;
I don't believe this will include the directories inside the Archive directory. Adding -type d does not work; -type is not a valid switch here. It seems to be valid in DDWRT but not in Merlin.
Here's a quick test:
RT-N66U:/jffs/scripts# find /tmp/mnt/sdb1/Left/ -type d -mtime +15 -exec ls -lh {} \;
find: unrecognized: -type
BusyBox v1.20.2 (2015-01-09 00:44:43 EST) multi-call binary.
Usage: find [PATH]... [OPTIONS] [ACTIONS]
Search for files and perform actions on them.
First failed action stops processing of current file.
Defaults: PATH is current directory, action is '-print'
-follow Follow symlinks
Actions:
! ACT Invert ACT's success/failure
ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2
ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2
Note: -a has higher priority than -o
-name PATTERN Match file name (w/o directory name) to PATTERN
-iname PATTERN Case insensitive -name
-mtime DAYS mtime is greater than (+N), less than (-N),
or exactly N days in the past
If none of the following actions is specified, -print is assumed
-print Print file name
-print0 Print file name, NUL terminated
-exec CMD ARG ; Run CMD with all instances of {} replaced by
file name. Fails if CMD exits with nonzero
There is a directory in there:
RT-N66U:/tmp/mnt/sdb1/Left# ls -lh |grep -i archive
drwxrwxrwx 2 Admin root 704.0K Feb 24 01:00 Archive
+++
Any other suggestions as how I can accomplish this? I don't mind if it blows out all the files AND directories. I just need the directories gone.
Last edited: