הכל קובץ בלינוקס כולל ספריה. ספריה היא רק קבוצת קבצים.
ישנן בעיקר שתי פקודות שמוחקות קבצים וספריות בלינוקס:
rm
rmdir
ה rmdir
הפקודה משמשת למחיקת ספריה ריקה בלינוקס.
לדוגמא, הקוד הבא מוחק את ספריית 'התמונות' שאין בה קבצים:
$ rmdir images/
אנו יכולים גם להשתמש ב- rm
פקודה עם -d
אפשרות למחיקת ספרייה ריקה:
$ rm -d images/
הערה:אם יש קבצים בתוך הספרייה, איננו יכולים להשתמש בהם rmdir למחיקת הספרייה.אם ננסה את הפקודה הנ'ל בספריה שאינה ריקה, היינו מקבלים:
$ rmdir images/ rmdir: images/: Directory not empty
כדי למחוק ספריה עם כל התוכן שלה באופן רקורסיבי, השתמש ב rm
פקודה עם ויכוח -r
.
$ rm -r images/
אתה יכול גם למחוק ספריה וכל התוכן שלה בכוח עם -rf
טַעֲנָה.
$ rm -rf images/
כדי למחוק קובץ בלינוקס, פשוט השתמש ב rm
פקודה:
$ rm cat.gif
כדי לאלץ מחיקת קובץ, השתמש ב -f
אפשרות עם rm
פקודה:
$ rm -f cat.gif
אם ברצונך להתבקש לאשר לפני מחיקת קובץ או ספריה, השתמש ב -i
אפשרות עם rm
פקודה:
$ rm -i cat.gif remove cat.gif? y
כדי לראות פלט של הקבצים שנמחקו השתמש -v
אוֹפְּצִיָה:
$ rm -v cat.gif cat.gif
כדי למחוק קבצים מרובים בפעולה אחת, אנו משתמשים ב- *
תו כללי.
לדוגמא, הקוד הבא מוחק את כל התמונות עם .gif
סיומת:
ls images/ bird.png cat.gif dog.gif rm *.gif ls images/ bird.png
rm [-dfiPRrvW] file ...
הטבלה שלהלן מציגה את השימוש ב- rm
פקודה עם כל האפשרויות שלה.
+--------+---------------------------------------------------------------------------------------------------------------------+-----+-----+ | Option | Description
|
|
| +--------+---------------------------------------------------------------------------------------------------------------------+-----+-----+ | -d
| Attempt to remove directories as well as other types of files.
|
|
| | -f
| Attempt to remove the files without prompting for confirmation, regardless of the file's permissions.
|
|
| | -i
| Request confirmation before attempting to remove each file, regardless of the file's permissions
|
|
| | -P
| Overwrite regular files before deleting them.
|
|
| | -R
| Attempt to remove the file hierarchy rooted in each file argument.
|
|
| | -r
| Same as -R
|
|
| | -v
| Be verbose when deleting files, showing them as they are removed.
|
|
| | -W
| Attempt to undelete the named files. Currently, this option can only be used to recover files covered by whiteouts. |
|
| +--------+---------------------------------------------------------------------------------------------------------------------+-----+-----+