Perl delete all files in a directory
my $errors;
while ($_ = glob('/tmp/* /tmp/.*')) {
next if -d $_;
unlink($_)
or ++$errors, warn("Can't remove $_: $!");
}
exit(1) if $errors;
You can use this. You need to use glob for removing files:
unlink glob "'/tmp/*.*'";
These extra apostrophes are needed to handle filenames with spaces as one string.