I alias rm
to rm -i
so that when I mistype file*
as file *
I get prompted before accidentally deleting files I didn't intend to delete. Is there an equivalent idiom for directories?
In particular, to delete a directory and its contents, you have to rm -r
. Using rm -ri
will prompt you for all the files in it, not just the top-level directory. For directories with a lot of files, that's not convenient. To avoid that, I frequently use rm -rf
, but that scares me. I'm only a typo away from blowing away lots of important stuff (e.g. rm -rf ~ /foo
instead of rm -rf ~/foo
—ouch!).
One could write a mildly annoying script to replace, e.g., rmdir with something that only prompts for the things listed on the command line, but it seems like this is the kind of problem for which a solution should already exist.
rm -rf ~/foo
, but by defaultcd ~; rm -rf foo/
I think it is mostly a matter of good habbits. – Bernhard Mar 13 '13 at 18:20&&
instead of;
, otherwise you way delete the wrong directory if thecd
fails for some reason. – jordanm Mar 13 '13 at 18:53