[Linux Learning] Essential Linux Commands (1) – Detailed explanation of the rm command
1.Detailed explanation of commands
The rm command is mainly used to delete files or directories. The usage is rm –rf test.txt (-r means recursion, -f means force). The common parameters are explained in detail below:
用法:rm [选项] 文件 删除 (unlink) 文件。
-f, --force 强制删除。忽略不存在的文件,不提示确认;
-i 在删除前需要确认;
-I 在删除超过三个文件或者递归删除前要求确认。此选项比-i
提示内容更少,但同样可以阻止大多数错误发生;
-r, -R, --recursive 递归删除目录及其内容;
-d, --dir 删除空目录
-v, --verbose 详细显示进行的步骤;
--help 显示此帮助信息并退出;
--version 显示版本信息并退出;
默认时,rm 不会删除目录,使用--recursive(-r 或-R)选项可删除每个给定的目录,以
及其下所有的内容;
要删除第一个字符为"-"的文件 (例如"-foo"),可使用:rm -- -foo或rm ./-foo
2. Command case
Forced deletion of directories and files
[root@nie linux]# rm -rf word1 word2 word3
[root@nie linux]# ls
test.txt word
Delete directories and files after confirmation
[root@nie linux]# rm -di word1
rm:是否删除目录 'word1'?y
[root@nie linux]# ls
test.txt word word2 word3 word4
[root@nie linux]# rm -i test.txt
rm:是否删除普通文件 'test.txt'?y
[root@nie linux]# ls
word
If there are more than three files, delete the directory and files after confirmation.
[root@nie linux]# rm -dI word1 word2 word3 word4
rm: remove 4 arguments? y
[root@nie linux]# ls
test.txt word
[root@nie linux]# rm -I test.txt test2.txt test3.txt test4.txt
rm: remove 4 arguments? y
[root@nie linux]# ls
word