Not-So-Stupid(?) Linux Trick

Here’s a command that can sometimes look a bit unnerving in operation, but is actually quite safe: rmdir -p «dir» where «dir» is some directory. Or to watch the whole process in action, add the option to give progress messages: rmdir -pv «dir» Background: the basic command rmdir «dir» deletes the named directory, but only if it is empty. The “-p” option takes this further, by then trying to delete the parent of «dir», and if that succeeds, the parent of that, and so on. It stops only when it gets to a nonempty directory, or when it has done all components of «dir». So if, for example, you try this on an absolute path, this will mean the command always stops on an error. And the error could quite likely be on a directory which contains important stuff that you care about. But, as I said, it’s quite safe, since it won’t delete that stuff. But I told you it could be unnerving, didn’t I?
participants (1)
-
Lawrence D'Oliveiro