هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
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
الأكثر استخدامًا
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع 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.
لا يوجد شيء يطابق هذا الفلتر.
انتبه
نصائح للحفظ
- rmdir = safe (empty only).
rm -r= everything inside too.