rmdir(2)

๐Ÿ’– rmdir(2) ๐Ÿ’–

okay so bestie, listen โ€” this is a page from the System Calls Manual, section 2, and it's literally just about deleting a directory. That's it. That's the whole vibe. Slay. ๐ŸŽ€

โœจ NAME โœจ

rmdir โ€” delete a directory

ngl the name is doing exactly what it says on the tin. no cap. ๐Ÿ’…

๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (that's libc, aka -lc) โ€” she's been here forever and she's not going anywhere. ๐Ÿ‘‘

๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <unistd.h>

int rmdir(const char *path);

that's the whole function signature, bestie. one arg, one int back. minimalism ate. โœจ

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so rmdir() deletes a directory. and here's the little catch that gets everybody: the directory has to be empty. like, actually empty. if there's a single file in there she's gonna look at you like ๐Ÿ™ˆ and refuse.

๐Ÿซถ RETURN VALUE ๐Ÿซถ

  • when it works? you get zero back. icon. ๐ŸŒˆ
  • when it doesn't? you get -1, and errno gets set to tell you exactly what went wrong. the way that errno is basically the group chat telling you where it all fell apart ๐Ÿ˜ญ

๐Ÿ”ฅ ERRORS ๐Ÿ”ฅ

okay so this is the big list, and every single one of these matters, so we're going through all of them, no skipping:

  • EACCES โ€” write access to the directory containing path was not allowed, OR one of the directories in the path prefix of path didn't allow search permission. (peep also path_resolution(7) for the full tea on how paths get resolved.) ๐Ÿšซ
  • EBUSY โ€” path is currently in use by the system, or by some process that's preventing its removal. On Linux specifically, that means path is currently being used as a mount point, or it's the root directory of the calling process. she's booked and busy, can't delete her. ๐Ÿ’€
  • EFAULT โ€” path points outside your accessible address space. girl. that's not yours. ๐Ÿ™ˆ
  • EINVAL โ€” path has . as last component. that's not it. ๐ŸŽ€
  • ELOOP โ€” too many symbolic links were encountered while resolving path. loop-de-loop, we're stuck. ๐ŸŒ€
  • ENAMETOOLONG โ€” path was too long. it's giving novel, not filename. ๐Ÿ˜ญ
  • ENOENT โ€” a directory component in path doesn't exist, or it's a dangling symbolic link. she's not there bestie. ๐Ÿ‘ป
  • ENOMEM โ€” insufficient kernel memory was available. kernel said "i'm full" ๐Ÿ“
  • ENOTDIR โ€” path, or a component used as a directory in path, is not, in fact, a directory. it's giving impostor. โœจ
  • ENOTEMPTY โ€” path contains entries other than . and ..; or, path has .. as its final component. also, POSIX.1 also allows EEXIST for this condition. (yes, they're both allowed, and no, I don't make the rules.) ๐Ÿซถ
  • EPERM โ€” the directory containing path has the sticky bit (S_ISVTX) set, and the process's effective user ID is neither the user ID of the file to be deleted nor that of the directory containing it, and the process is not privileged (on Linux: it doesn't have the CAP_FOWNER capability). sticky bit said no. ๐Ÿ’…
  • EPERM โ€” the filesystem containing path doesn't support the removal of directories. some filesystems literally just don't do this. ๐Ÿšซ
  • EROFS โ€” path refers to a directory on a read-only filesystem. read-only means read-only, bestie. ๐ŸงŠ
note that EPERM shows up twice up there, for two completely different reasons โ€” that's not a typo, that's just how it is. ๐Ÿ™‚โ€โ†•๏ธ

๐Ÿ›๏ธ STANDARDS ๐Ÿ›๏ธ

POSIX.1-2024. she's certified. ๐Ÿ“œโœจ

โญ HISTORY โญ

POSIX.1-2001, SVr4, 4.3BSD. she's been iconic since before you were born, fr fr. ๐Ÿ‘‘

๐Ÿ’€ BUGS ๐Ÿ’€

this is the cursed part: infelicities in the protocol underlying NFS can cause the unexpected disappearance of directories which are still being used.

so like. directories can just... vanish. that are still in use. nfs said "surprise" and honestly that's terrifying, no notes, be careful. ๐Ÿ˜ญ

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€


and that's the whole page bestie!! this one's from Linux man-pages 6.20, dated 2026-02-08 โ€” go delete an (empty) directory, you absolute legend ๐Ÿซถ๐ŸŒธ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms