هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
rm removes file names. When the last name of a file is gone (and no program has it open), the space is free. There is no trash can: a removed file is gone.
rm does not remove folders unless you add -r. -f removes without questions and without errors for missing files.
On RHEL, root has the alias rm='rm -i', so it asks for each file. rm also refuses to remove / itself (--preserve-root).
طريقة الكتابة
rm [OPTION]... FILE...الخيارات 12
الأكثر استخدامًا
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Remove a file
rm notes.txtThe file is gone; no undo.
2Remove a folder with its content
rm -r /tmp/buildAsks for each file when the rm -i alias is active (root on RHEL).
3Remove without any question
rm -rf /tmp/buildPowerful and dangerous. Check the path twice.
4Ask once for a big removal
rm -rI ~/old-projectsOne question instead of one per file.
5Remove files with a name that starts with a dash
rm -- -weird-name.txt--means: the options end here.6Remove old logs with find (safer than wildcards)
find /var/log/myapp -name "*.log" -mtime +30 -print -deleteRemoves logs older than 30 days and prints each name.
7Remove a file with spaces in its name
rm "My Report (final).docx"Quotes keep the name together.
8Test a wildcard before removing
echo /tmp/cache/*.tmp rm /tmp/cache/*.tmpechoshows exactly what the shell will pass to rm.9Free space that a deleted log still uses
A program that keeps a deleted file open still uses the space. Restart it to free the space.
10Stay on one file system
rm -rf --one-file-system /mnt/oldroot/tmpProtects mounted file systems below the folder from being wiped.
11Remove empty folders and files in one go
rm -dv empty-dir file.txt-dremoves the empty folder too.
لا يوجد شيء يطابق هذا الفلتر.
انتبه
- No trash, no undo. Make a copy first or use
mvto a temp folder when you are unsure. - Never put a variable alone in rm:
rm -rf "$DIR/"*with an empty DIR deletes from/. Use${DIR:?}. - A space in the wrong place:
rm -rf / tmp/xdeletes everything. Read the line before Enter.
نصائح للحفظ
- File:
rm. Folder:rm -r. No questions:-f. One question:-I. - In scripts:
rm -rf "${DIR:?}/"*stops when DIR is empty.