الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

rmdir

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

المستوى
امتحان RHCSA
المجموعة
الملفات والمجلدات
يحتاج root
لا
الحزمة
coreutils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

rmdir [OPTION]... DIRECTORY...

الخيارات 5

الأكثر استخدامًا

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

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع 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.

انتبه

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

نصائح للحفظ

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man rmdir