If you need portability with slightly older busybox versions, whose find doesn't have -delete, the most efficient and secure solution I could find is:
find dontDeleteMe/ -mindepth 1 -maxdepth 1 -exec rm -rfv -- '{}' +
Or, for less verbose output the doesn't report every deleted file and directory:
find dontDeleteMe/ -mindepth 1 -maxdepth 1 -exec rm -rf -- '{}' +
Security advice: Better over-use than under-use the -- argument! This protects against path names starting with a - character, which would otherwise be misinterpreted as additional rm flags.
(Admittedly, in this specific find invocation it is hard to trigger that case, given that all arguments to rm are prefixed by dontDeleteMe/, and even if that came from a variable and started with -, it would likely have confused find rather than being passed to rm. But the mere fact that you need these complex kind of reasoning for security should be already a red flag to you. It is wiser to just stick to -- and be done with it.)
Another important detail: Note that the trailing slash of dontDeleteMe/ is optional if dontDeleteMe is a plain directory, but mandatory if dontDeleteMe is a symlink to the actual directory. I recommend to just keep the trailing / to ensure it works as expected in all present and future situations.
How this whole command works: By setting -mindepth as well as -maxdepth to 1, this steps only through the direct files and subdirectories, letting the -r option of rm take care of the actual recursion in the deletion. The + operator of find collects multiple arguments for the rm to provide a minimum total number of rm invocations (in most cases, just one invocation), similar to what xargs does.
find dontDeleteMe/* -print0 | xargs -0 rm -rvI believe in most cases this will work, regardless of spaces, and what not. But cd to/tmp/and make a test directory and try it out. :) – Matt Nov 01 '11 at 22:42rm -rf dontDeleteMe && mkdir dontDeleteMedoesn't ensure that the dir is re-created with the same permissions/owner(s). Instead, use one of thefind dontDeleteMe/ -mindepth 1 -deletevariants below. – Nils Toedtmann Jan 15 '15 at 13:31