RMDIR(2)
π RMDIR(2) π
okay bestie, so this one is a page from the System Calls Manual (yes, the 2 section, we love a syscall moment) and it's all about the rmdir system call. let's get into it π«Ά
β¨ NAME β¨
rmdir β remove a directory file. that's it. that's the whole vibe. bye-bye empty folder π
π LIBRARY π
Standard C Library (libc, -lc). so like, link against -lc and you're golden β¨
π SYNOPSIS π
#include <unistd.h>
int
rmdir(const char *path);
like, that's the whole signature. one path, one int coming back at you π
π¦ DESCRIPTION π¦
so the rmdir() system call removes a directory file whose name is given by path.
and here's the tea β β the directory must not have any entries other than β.β and β..β. it has to be empty empty. not "empty-ish". not "just one little file". literally just . and .. and nothing else. if there's anything else in there, bestie, it's not happening π
π RETURN VALUES π
rmdir()returns the value0if it succeeded. slay β¨- otherwise the value
-1comes back and the global variableerrnois set to tell you exactly what went wrong. iconic error-reporting behaviour, honestly π
π ERRORS π
so the named file is removed unless one of these lil guys happens. read 'em and weep:
[ENOTDIR]β a component of the path is not a directory. rude of it.[ENAMETOOLONG]β a component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. that's a LOT of characters bestie, calm down π[ENOENT]β the named directory does not exist. it's giving "who?" π[ELOOP]β too many symbolic links were encountered in translating the pathname. the symlinks got into a situationship and never came out π[ENOTEMPTY]β the named directory contains files other thanβ.βandβ..βin it. we told you it had to be empty π€[EACCES]β search permission is denied for a component of the path prefix.[EACCES]β write permission is denied on the directory containing the link to be removed.[EPERM]β the directory to be removed has its immutable, undeletable or append-only flag set, see thechflags(2)manual page for more information. yeah it's flagged, you cannot simply delete it π©[EPERM]β the parent directory of the directory to be removed has its immutable or append-only flag set. the parent said "not on my watch" π[EPERM]β the directory containing the directory to be removed is marked sticky, and neither the containing directory nor the directory to be removed are owned by the effective user ID. sticky-bit drama, we love to see it π[EINVAL]β the last component of the path isβ.βorβ..β. nope. absolutely not. you cannot rmdir the dot-dots, that's the rules π«[EBUSY]β the directory to be removed is the mount point for a mounted file system. busy busy busy, it's got a whole filesystem hanging off it π[EIO]β an I/O error occurred while deleting the directory entry or deallocating the inode. hardware said nope π[EINTEGRITY]β corrupted data was detected while reading from the file system. πππ[EROFS]β the directory entry to be removed resides on a read-only file system. it's read-only babes, you literally cannot β[EFAULT]β thepathargument points outside the process's allocated address space. the pointer went somewhere it should not have gone, main character energy gone wrong π«
πΈ SEE ALSO πΈ
mkdir(2), unlink(2) β the make-the-folder one and the delete-the-file one. the whole bestie trio fr fr π«Ά
β HISTORY β
the rmdir() system call appeared in 4.2BSD. vintage! retro! still here! π
ngl bestie, if you remember ONE thing: the directory must be empty except forβ.βandβ..β. that's the whole personality of this syscall. no cap. π
and that's the page!! this one came from Debian, dated March 30, 2020, and it lives at RMDIR(2). mwah, go delete an empty folder responsibly πβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms