2 ms·
Works on any Unix-like system, from Solaris to AIX to Mac OS X. If a directory is empty, remove it with "rmdir". (It is safer to implement a cleanup script as
by makecheck 15y ago
Works on any Unix-like system, from Solaris to AIX to Mac OS X.
If a directory is empty, remove it with "rmdir". (It is safer to implement a cleanup script as a series of "rm" commands for files and "rmdir" files for directories; that way, if the directory happens to contain anything you didn't expect, the unknown files will be preserved. The "rm -rf" approach is a bit of a sledgehammer that can have unintended side effects.)
A particular gotcha on Linux is that a trailing slash on a directory path follows symlinks, whereas a lack of a trailing slash does not. This means that "rm -rf xyz" is very different than "rm -rf xyz/" if "xyz" is a symbolic link to a directory: the first one deletes the link only, and the second one deletes the entire directory that the link points to!
Symlinks are also misleading when mounted by other operating systems; e.g. when mounting a network drive on Windows. Deleting (from Windows) an item that happens to be a symlink on the Unix side will have the effect of following that link and destroying an entire destination file or directory, which is different than what "rm" would do in the Unix shell for the same path.