← 返回命令列表

Linux command

rm 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Remove a file

rm [file]

Remove multiple files

rm [file1] [file2] [file3]

Remove a file with confirmation prompt

rm -i [file]

Remove a directory and its contents recursively

rm -r [directory]

Force remove without confirmation

rm -f [file]

Force remove a directory recursively

rm -rf [directory]

Remove files verbosely

rm -v [file]

Remove files matching a pattern

rm *.tmp

说明

rm removes files and directories. By default, it does not remove directories; use -r to remove directories recursively. Without -f, rm prompts for confirmation when removing write-protected files. With -i, it prompts for every file. The -I option provides a middle ground, prompting once for potentially dangerous operations. To remove a file starting with a dash, use -- to end option processing: rm -- -filename or use a path: rm ./-filename. The command unlinks files from the filesystem. Data may be recoverable until overwritten. For secure deletion, use shred.

参数

-f, --force
Ignore nonexistent files, never prompt
-i
Prompt before every removal
-I
Prompt once before removing more than 3 files or recursively
-r, -R, --recursive
Remove directories and their contents recursively
-d, --dir
Remove empty directories
-v, --verbose
Explain what is being done
--no-preserve-root
Do not treat '/' specially (dangerous)
--preserve-root
Do not remove '/' (default)
--one-file-system
When removing recursively, skip directories on different filesystems

FAQ

What is the rm command used for?

rm removes files and directories. By default, it does not remove directories; use -r to remove directories recursively. Without -f, rm prompts for confirmation when removing write-protected files. With -i, it prompts for every file. The -I option provides a middle ground, prompting once for potentially dangerous operations. To remove a file starting with a dash, use -- to end option processing: rm -- -filename or use a path: rm ./-filename. The command unlinks files from the filesystem. Data may be recoverable until overwritten. For secure deletion, use shred.

How do I run a basic rm example?

Run `rm [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -f, --force do in rm?

Ignore nonexistent files, never prompt