Hi all, this is my first post, so please be gentle...
I have a situation wherby I need a script that traverses known paths. Check for the modified date (n days) and then deletes all subdirs.
I have come up with this hotch potch, but as far as I can tell it seems to work.
What I am wondering is there any other way to make this cleaner?
Any help would be appreciated.
Oh this is on a QNAP NAS (busybox I think)
Create 2 files
Includes-file (this contains all the path statements.i.e. /path1/subdir /path2/subdir/subdir etc)
The script itself (del.sh)
Here is the script:
#!/opt/bin/bash
# cat all paths to cd
for i in `cat includes-file`;do
# find all directories in paths that have been modified more than 70 days ago and then delete them
cd $i; for path in `/opt/bin/find . -maxdepth 1 -mtime +70` ; do rm -rf $path
done
done
I have put in Yazu's code, tested and works. I had a programmer at work explain the finder points of your script. I have never used "read" before.
Final code:
#!/opt/bin/bash
while read p; do
find "$p" -maxdepth 1 -type d -mtime +60 | xargs "rm -rf %s\n"
done <includes-file
Once again, thank you for taking the time to look at this issue. It will be a big help to our organisations rolling backup regime.