Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

rmdir

Remove empty folders (and refuse to remove folders that still have files).

Niveau
RHCSA-examen
Groep
Bestanden en mappen
Root nodig
Nee
Pakket
coreutils

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

-p, --parents
Remove the folder and then each parent in the path, as long as they are empty.
-v, --verbose
Print a line for each folder removed.
--ignore-fail-on-non-empty
Do not show an error for folders that are not empty.
--help
Show help.
--version
Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Remove an empty folder

    rmdir old-reports

    Fails with "Directory not empty" if there is still something inside.

  2. 2Remove a path of empty folders

    rmdir -p a/b/c

    Removes c, then b, then a (if they are all empty).

  3. 3Remove all empty folders in a tree

    find /srv/uploads -type d -empty -delete

    rmdir works per folder; find -empty -delete cleans a whole tree.

  4. 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.

  5. 5Show what is removed

    rmdir -v /tmp/test
    rmdir: removing directory, '/tmp/test'

    Useful in logs.

  6. 6Find out why a folder is not empty

    rmdir /tmp/x || ls -A /tmp/x

    Hidden files (starting with a dot) often keep a folder "not empty".

  7. 7Remove an empty mount point after unmount

    umount /mnt/usb && rmdir /mnt/usb

    rmdir also protects you: it fails if the disk is still mounted with files.

  8. 8Clean empty release folders in a deploy script

    rmdir --ignore-fail-on-non-empty /srv/app/releases/* 2>/dev/null

    Old empty folders go away, used ones stay.

  9. 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.

  10. 10Remove several empty folders at once

    rmdir logs tmp cache

    Each one must be empty.

  11. 11Check if a folder is empty before removing it in a script

    [ -z "$(ls -A /var/spool/app)" ] && rmdir /var/spool/app

    ls -A prints nothing when the folder is empty.

Let op

  • rmdir never deletes files. When it says "not empty", look with ls -A before you switch to rm -r.

Tips om te onthouden

  • rmdir = safe (empty only). rm -r = everything inside too.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man rmdir