Recreating the directory seems a pretty clean way to do it.
find /data1 -name MyTargetDir -type d -exec rm -rv {} \; -exec mkdir {} \;
You could instead use a subshell in the exec to run a rm -rf * (or similar) from within the directory. But that just seems more trouble than the above. You have the side effect of cleaning up the directory size if that were ever a problem.
As mentioned, recreating the directory may be too much of a problem. If so, an alternative could be:
find /data1 -name MyTargetDir -type d -exec bash "-c" "cd {} && rm -r -- * .*" \;
This has the unfortunate problem of whining about attempts to remove "." and "..", but it should be safe.
Otherwise, you can just go for a full-on script solution, such as perl.
#!/path/to/perl
use strict;
use warnings;
use File::Find;
use File::Path qw/remove_tree/;
my ($dir_to_check, $name_to_remove) = @ARGV;
find(\&wanted, $dir_to_check);
sub wanted {
if (-d and $_ eq $name_to_remove) {
remove_tree($_, {keep_root => 1});
}
}
Pass in the directory first and the name to match second. It's no longer a shell one-liner, but it works, doesn't destroy the directory, and doesn't spit out any spurious warnings.
find <dir> ! -type d -exec rm {} +