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?

The use of a relative path is a good thing, but this is incomplete. Paranoia should take control of when you use a destructive command and you should never make assumptions.

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