Linux 基础命令 -- rm

命令介绍

命令:rm 删除文件

用法:rm [OPTION]… FILE… rm 选项 文件

命令选项

[root@fp-21 ~]# rm --help

  -f, --force           # 强制,不提示是否删除
  -i                    # 每次删除前都提示( 默认参数 
  -I                    # 在删除三个以上的文件之前或递归删除文件( 目录 )时提示
  -r, -R, --recursive   # 递归删除目录及其内容
  -d, --dir             # 删除空目录
  -v, --verbose         # 删除时显示详细信息
  --help                # 帮助文档
  --version             # 版本信息

命令实例

# 每次删除前都提示( 默认参数 )
[root@fp-21 tmp]# rm a.txt
rm: remove regular file ‘a.txt’? y

# 强制,不提示
[root@fp-21 tmp]# rm -f a.txt 
[root@fp-21 tmp]# ll a.txt
ls: cannot access a.txt: No such file or directory

# 在删除三个以上的文件之前或递归删除文件( 目录 )时提示
[root@fp-21 tmp]# touch {1..3}.txt
[root@fp-21 tmp]# rm -I 1.txt 2.txt 3.txt 
[root@fp-21 tmp]# touch {1..4}.txt
[root@fp-21 tmp]# rm -I 1.txt 2.txt 3.txt 4.txt 
rm: remove 4 arguments? y

# 删除时显示详细信息
[root@fp-21 tmp]# rm -rfv a.txt 
removed ‘a.txt’

在操作过程中,不小心多了一个 - 号,此时想要去删除,会遇到一些问题

[root@fp-21 tmp]# echo "test_file" > -foo
[root@fp-21 tmp]# ll
total 8
-rw-r--r--. 1 root root  10 Feb 23 14:49 -foo
[root@fp-21 tmp]# rm -rf -foo
rm: invalid option -- 'o'
Try 'rm ./-foo' to remove the file ‘-foo’.
Try 'rm --help' for more information.

有两种方案可以解决以上的问题

[root@fp-21 tmp]# rm -- -foo
rm: remove regular file ‘-foo’? y

[root@fp-21 tmp]# echo "test_file" > -foo
[root@fp-21 tmp]# rm ./-foo
rm: remove regular file ‘./-foo’? y

link 查看 Linux 基础命令

只有注入思想的博客才是好的博客

发布了33 篇原创文章 · 获赞 145 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/xtlhxl/article/details/104460155