Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
rmdir deletes a folder only when it is empty. That makes it a safe tool: it cannot delete files by accident. To delete a folder with content, use rm -r.
With -p it also removes the parent folders when they become empty.
Zo schrijf je het
rmdir [OPTION]... DIRECTORY...Opties 5
Meest gebruikt
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1Remove an empty folder
rmdir old-reportsFails with "Directory not empty" if there is still something inside.
2Remove a path of empty folders
rmdir -p a/b/cRemoves c, then b, then a (if they are all empty).
3Remove all empty folders in a tree
find /srv/uploads -type d -empty -deletermdir works per folder;
find -empty -deletecleans a whole tree.4Try to remove folders, ignore the ones that are not empty
rmdir --ignore-fail-on-non-empty /tmp/build/*/Only the empty ones are removed, no error messages.
5Show what is removed
rmdir -v /tmp/test rmdir: removing directory, '/tmp/test'Useful in logs.
6Find out why a folder is not empty
rmdir /tmp/x || ls -A /tmp/xHidden files (starting with a dot) often keep a folder "not empty".
7Remove an empty mount point after unmount
umount /mnt/usb && rmdir /mnt/usbrmdir also protects you: it fails if the disk is still mounted with files.
8Clean empty release folders in a deploy script
rmdir --ignore-fail-on-non-empty /srv/app/releases/* 2>/dev/nullOld empty folders go away, used ones stay.
9Remove a folder with a strange name
rmdir -- -tmp---ends the options, so a name that starts with a dash is not read as an option.10Remove several empty folders at once
rmdir logs tmp cacheEach one must be empty.
11Check if a folder is empty before removing it in a script
[ -z "$(ls -A /var/spool/app)" ] && rmdir /var/spool/appls -Aprints nothing when the folder is empty.
Niets past bij dit filter.
Let op
Tips om te onthouden
- rmdir = safe (empty only).
rm -r= everything inside too.