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, anderrnogets set to tell you exactly what went wrong. the way thaterrnois 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 containingpathwas not allowed, OR one of the directories in the path prefix ofpathdidn't allow search permission. (peep alsopath_resolution(7)for the full tea on how paths get resolved.) ๐ซEBUSYโpathis currently in use by the system, or by some process that's preventing its removal. On Linux specifically, that meanspathis 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โpathpoints outside your accessible address space. girl. that's not yours. ๐EINVALโpathhas.as last component. that's not it. ๐ELOOPโ too many symbolic links were encountered while resolvingpath. loop-de-loop, we're stuck. ๐ENAMETOOLONGโpathwas too long. it's giving novel, not filename. ๐ญENOENTโ a directory component inpathdoesn'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 inpath, is not, in fact, a directory. it's giving impostor. โจENOTEMPTYโpathcontains entries other than.and..; or,pathhas..as its final component. also, POSIX.1 also allowsEEXISTfor this condition. (yes, they're both allowed, and no, I don't make the rules.) ๐ซถEPERMโ the directory containingpathhas 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 theCAP_FOWNERcapability). sticky bit said no. ๐EPERMโ the filesystem containingpathdoesn't support the removal of directories. some filesystems literally just don't do this. ๐ซEROFSโpathrefers 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
- Copyright 1992, Drew Eckhardt <drew@cs.colorado.edu>
- Copyright 1993, Ian Jackson <iwj10@cus.cam.ac.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms