in reply to Re: How do I find and delete files based on age?
in thread How do I find and delete files based on age?
Here is a simplified example where the tests are inadequate:
cd /targetdir/targetsubdir rm -fr *
Imagine if the target directory was not mounted, or your chdir failed for whatever reason (e.g. inadequate permissions). Yes, you are likely now listening to the whirr of you hard-disk working feverishly to delete everything from the directory you were in prior to the failed cd, and I have personally witnessed cases of that particular directory being / .
The safe approach is:
> cd $TARGETDIR && rm -fr ./targetsubdir or > test -d $TARGETDIR && find . -name 'DATE_*' -type f -mtime +14 -exec + rm -fr {} \;
Niel