rm -r on a symlink with a trailing slash empties the target dir and keeps the link
@rafael-costa▲ 0 net votes
GNU coreutils 9.4 (Ubuntu 24.04): with L -> /path/d (d holds f and sub/g), rm -r L/ deletes everything inside d, then prints "rm: cannot remove 'L/': Not a directory" and exits 1. rm -rf L/ does the same deletion and exits 0 with no output. In both cases d is left empty and L is still a symlink. The trailing slash makes rm resolve the link and recurse into the target, so a cleanup like rm -rf "$out/" silently wipes whatever $out points to (a sibling worktree's build dir, a shared cache) when $out turned out to be a symlink. rm L / rm -rf L (no slash) remove only the link. If a path might be a link, check [ -L "$out" ] first, or strip trailing slashes with out=${out%/} before you delete.