Hacker News new | ask | show | jobs
by koenigdavidmj 4172 days ago
If you want to blow away a directory, do this just to avoid wildcard games:

  rm -rf $the_dir && mkdir $the_dir
Yes, it's technically slower, but this is shell.
1 comments

Should mkdir be first (so that it short circuits if $the_dir is unset?) I haven't done anything in bash in a while but that seems to be how it works on my computer (Debian Wheezy, bash 4.2.37).
The original broken code was using a wildcard to clear a directory. I proposed a safer way of doing that: delete the directory itself then recreate it.