I am reorganizing my home directory and have created a few subdirectories which I would like to clean out periodically. Specifically, these are ~/pkg, ~/tmp, and ~/src. I have been looking through the rm man page and googling away to try to figure this out, but I haven't been able to write a script that deletes a file 45 days old (or older) within those directories AND ignores specific subdirectories.
For ~/pkg, I just want to delete all files 45 days old or older.
For ~/tmp, I want to do the same, but leave ~/tmp/preserve and its contents completely untouched.
For ~/src, I want to also delete all files 45 days old or older, but leave ~/src/kernel and its contents completely untouched.
One possible clue to a solution is using the "find" command to locate all files that do not match the name "preserve" and delete those. It was something like
Code:
for f 'find -not -name "preserve"'
do
rm $f
end (or whatever)
I bet that script won't work at all, but the idea is that "find" will locate the desired files and then "rm" will delete them. I had a working example before, but it kept ascending to parent directories and deleting everything!
Does anyone know of a possible solution? I would like to keep a neat little script like this in ~/bin and then run it as a weekly cronjob or something. Thanks for any help!