Instead of using “rm -rf”
The slightly safer alternative is
$ rm --one-file-system -vrf delme-junk/
There are two additional flags:
- The -v flag causes “rm” to display the files as it deletes them. This gives the user a chance to stop the process if something completely wrong happens. Not as good as thinking before making the mistake, but much better than understanding the it in hindsight.
- The –one-file-system flag prevents deleting files from possibly mounted sub-filesystems. For example, deleting a directory tree that contains bind mounts (a chroot jail, for example), forgetting to unmount these beforehand.
This is no substitute to thinking before typing, of course. ;)
Also, renaming the directory to a name that clearly means it should be deleted is helpful too. In particular as the operation is stored in the command history, with the potential of being re-run accidentally. Even though one may exempt the command from being stored with a space as the first character in the command line, if bash is configured accordingly.