Linux删除用什么命令,linux删除文件或目录用什么命令?

63818a21f268f6a6e2980ac5f5218461.png

还是学生吗?我们都自己买资料看,记本记可记不全呀,《Linux指令速查手册》

【语法】rm[必要参数][选择性参数][目录或者文件]

【功能说明】rm指令用来删除文件或者目录,如果使用rm来删除文件,通常仍可以将文件恢复。如果想保证该文件的内容无法复原,可以考虑使用shred指令。

【参数说明】

必要参数具体说明如下:

参数 功能

-d 删除可能仍有数据的目录

-f 强制删除

-i 交互模式

-r 同时删除该目录下的所有目录层

-v 运行时显示详细的信息

选择性参数的具体说明如下:

参数 功能

--help 帮助信息

--version 版本信息

【执行范例】

【范例560】删除文件。

[root@localhost kk]# ll //显示文件的详细信息

总用量 7400

-rw-r--r-- 1 root root 8997 5月22 10:21 111

-rw-r--r-- 1 root root 53 5月14 09:40 abc.c

-rw-r--r-- 1 root root 97 5月13 15:53 a.c

-rw-r--r-- 1 root root 97 5月13 15:42 a.c~

-rw-r--r-- 1 root root 97 5月13 15:46 a.c@

-rw-r--r-- 1 root root 5867520 5月28 14:53 bu

-rw-r--r-- 1 root root 100 5月14 09:40 chch.c

-rw-r--r-- 1 root root 205 5月14 09:11 cmh.c

-rw-r--r-- 1 root root 7376 5月14 09:11 D.c

drwxr-xr-x 2 root root 4096 5月13 15:57 Desktop

-rw-r--r-- 1 root root 675 5月14 09:11 fcntl.c

-rw-r--r-- 1 root root 225 5月14 09:11 file.c

-rw-r--r-- 1 root root 497 5月14 09:11 findconf.c

-rw-r--r-- 1 root root 505 5月14 09:11 getcurtime.c

-rw-r--r-- 1 root root 296 5月14 09:11 getsec.c

-rw-r--r-- 1 root root 115 5月14 09:11 gettime.c

-rw-r--r-- 1 root root 513 5月14 09:11 getusec.c

-rw-r--r-- 1 root root 92 5月14 09:11 long.c

-rw-r--r-- 1 root root 126 5月14 09:11 max.c

-rw-r--r-- 1 root root 151 5月14 09:11 rand.c

-rw-r--r-- 1 root root 101 5月14 09:11 sprintf.c

-rw-r--r-- 1 root root 131 5月14 09:11 strrchr.c

-rw-r--r-- 1 root root 1563 5月22 10:09 test

-rw-r--r-- 1 root root 1471488 5月 3 16:10 unpv12e.tar

-rw-r--r-- 1 root root 142 5月14 09:11 wenjian.c

-rw-r--r-- 1 root root 474 5月14 09:11 zuobiao.c

[root@localhost kk]# rm zuobiao.c //删除文件

[root@localhost kk]# ll //显示文件

总用量 7392

-rw-r--r-- 1 root root 8997 5月22 10:21 111

-rw-r--r-- 1 root root 53 5月14 09:40 abc.c

-rw-r--r-- 1 root root 97 5月13 15:53 a.c

-rw-r--r-- 1 root root 97 5月13 15:42 a.c~

//此处省略了部分结果

-rw-r--r-- 1 root root 1563 5月22 10:09 test

-rw-r--r-- 1 root root 1471488 5月 3 16:10 unpv12e.tar

-rw-r--r-- 1 root root 142 5月14 09:11 wenjian.c

[root@localhost kk]#

本例使用指令“rm zuobiao.c”,删除文件zuobiao.c。

【范例561】删除文件夹。

[root@localhost kk]# ll //显示文件信息

总占用量 7400

-rw-r--r-- 1 root root 8997 5月22 10:21 111

-rw-r--r-- 1 root root 53 5月14 09:40 abc.c

-rw-r--r-- 1 root root 97 5月13 15:53 a.c

-rw-r--r-- 1 root root 97 5月13 15:42 a.c~

-rw-r--r-- 1 root root 97 5月13 15:46 a.c@

-rw-r--r-- 1 root root 5867520 5月28 14:53 bu

-rw-r--r-- 1 root root 100 5月14 09:40 chch.c

-rw-r--r-- 1 root root 205 5月14 09:11 cmh.c

-rw-r--r-- 1 root root 7376 5月14 09:11 D.c

drwxr-xr-x 2 root root 4096 5月13 15:57 Desktop

-rw-r--r-- 1 root root 675 5月14 09:11 fcntl.c

-rw-r--r-- 1 root root 225 5月14 09:11 file.c

-rw-r--r-- 1 root root 497 5月14 09:11 findconf.c

-rw-r--r-- 1 root root 505 5月14 09:11 getcurtime.c

-rw-r--r-- 1 root root 296 5月14 09:11 getsec.c

-rw-r--r-- 1 root root 115 5月14 09:11 gettime.c

-rw-r--r-- 1 root root 513 5月14 09:11 getusec.c

-rw-r--r-- 1 root root 92 5月14 09:11 long.c

-rw-r--r-- 1 root root 126 5月14 09:11 max.c

-rw-r--r-- 1 root root 151 5月14 09:11 rand.c

-rw-r--r-- 1 root root 101 5月14 09:11 sprintf.c

-rw-r--r-- 1 root root 131 5月14 09:11 strrchr.c

drwxr-xr-x 2 root root 4096 5月28 16:03 temp

-rw-r--r-- 1 root root 1563 5月22 10:09 test

-rw-r--r-- 1 root root 1471488 5月 3 16:10 unpv12e.tar

-rw-r--r-- 1 root root 142 5月14 09:11 wenjian.c

[root@localhost kk]# rm -rf temp/ //删除目录temp/

[root@localhost kk]# ll //显示文件信息

总占用量 7392

-rw-r--r-- 1 root root 8997 5月22 10:21 111

-rw-r--r-- 1 root root 53 5月14 09:40 abc.c

-rw-r--r-- 1 root root 97 5月13 15:53 a.c

-rw-r--r-- 1 root root 97 5月13 15:42 a.c~

-rw-r--r-- 1 root root 97 5月13 15:46 a.c@

-rw-r--r-- 1 root root 5867520 5月28 14:53 bu

-rw-r--r-- 1 root root 100 5月14 09:40 chch.c

-rw-r--r-- 1 root root 205 5月14 09:11 cmh.c

-rw-r--r-- 1 root root 7376 5月14 09:11 D.c

drwxr-xr-x 2 root root 4096 5月13 15:57 Desktop

-rw-r--r-- 1 root root 675 5月14 09:11 fcntl.c

-rw-r--r-- 1 root root 225 5月14 09:11 file.c

-rw-r--r-- 1 root root 497 5月14 09:11 findconf.c

-rw-r--r-- 1 root root 505 5月14 09:11 getcurtime.c

-rw-r--r-- 1 root root 296 5月14 09:11 getsec.c

-rw-r--r-- 1 root root 115 5月14 09:11 gettime.c

-rw-r--r-- 1 root root 513 5月14 09:11 getusec.c

-rw-r--r-- 1 root root 92 5月14 09:11 long.c

-rw-r--r-- 1 root root 126 5月14 09:11 max.c

-rw-r--r-- 1 root root 151 5月14 09:11 rand.c

-rw-r--r-- 1 root root 101 5月14 09:11 sprintf.c

-rw-r--r-- 1 root root 131 5月14 09:11 strrchr.c

-rw-r--r-- 1 root root 1563 5月22 10:09 test

-rw-r--r-- 1 root root 1471488 5月 3 16:10 unpv12e.tar

-rw-r--r-- 1 root root 142 5月14 09:11 wenjian.c

[root@localhost kk]#

本例使用指令“rm -rf temp/”,删除当前文件夹下的目录temp/。

【范例562】利用通配符删除文件。

[root@localhost kk]# ll //显示文件信息

总占用量 7392

-rw-r--r-- 1 root root 8997 5月22 10:21 111

-rw-r--r-- 1 root root 53 5月14 09:40 abc.c

-rw-r--r-- 1 root root 97 5月13 15:53 a.c

-rw-r--r-- 1 root root 97 5月13 15:42 a.c~

-rw-r--r-- 1 root root 97 5月13 15:46 a.c@

-rw-r--r-- 1 root root 5867520 5月28 14:53 bu

-rw-r--r-- 1 root root 100 5月14 09:40 chch.c

-rw-r--r-- 1 root root 205 5月14 09:11 cmh.c

-rw-r--r-- 1 root root 7376 5月14 09:11 D.c

drwxr-xr-x 2 root root 4096 5月13 15:57 Desktop

-rw-r--r-- 1 root root 675 5月14 09:11 fcntl.c

-rw-r--r-- 1 root root 225 5月14 09:11 file.c

-rw-r--r-- 1 root root 497 5月14 09:11 findconf.c

-rw-r--r-- 1 root root 505 5月14 09:11 getcurtime.c

-rw-r--r-- 1 root root 296 5月14 09:11 getsec.c

-rw-r--r-- 1 root root 115 5月14 09:11 gettime.c

-rw-r--r-- 1 root root 513 5月14 09:11 getusec.c

-rw-r--r-- 1 root root 92 5月14 09:11 long.c

-rw-r--r-- 1 root root 126 5月14 09:11 max.c

-rw-r--r-- 1 root root 151 5月14 09:11 rand.c

-rw-r--r-- 1 root root 101 5月14 09:11 sprintf.c

-rw-r--r-- 1 root root 131 5月14 09:11 strrchr.c

-rw-r--r-- 1 root root 1563 5月22 10:09 test

-rw-r--r-- 1 root root 1471488 5月 3 16:10 unpv12e.tar

-rw-r--r-- 1 root root 142 5月14 09:11 wenjian.c

[root@localhost kk]# rm -f f* //删除文件

[root@localhost kk]# ll //显示文件信息

总占用量 7368

-rw-r--r-- 1 root root 8997 5月22 10:21 111

-rw-r--r-- 1 root root 53 5月14 09:40 abc.c

-rw-r--r-- 1 root root 97 5月13 15:53 a.c

-rw-r--r-- 1 root root 97 5月13 15:42 a.c~

-rw-r--r-- 1 root root 97 5月13 15:46 a.c@

-rw-r--r-- 1 root root 5867520 5月28 14:53 bu

-rw-r--r-- 1 root root 100 5月14 09:40 chch.c

-rw-r--r-- 1 root root 205 5月14 09:11 cmh.c

-rw-r--r-- 1 root root 7376 5月14 09:11 D.c

drwxr-xr-x 2 root root 4096 5月13 15:57 Desktop

-rw-r--r-- 1 root root 505 5月14 09:11 getcurtime.c

-rw-r--r-- 1 root root 296 5月14 09:11 getsec.c

-rw-r--r-- 1 root root 115 5月14 09:11 gettime.c

-rw-r--r-- 1 root root 513 5月14 09:11 getusec.c

-rw-r--r-- 1 root root 92 5月14 09:11 long.c

-rw-r--r-- 1 root root 126 5月14 09:11 max.c

-rw-r--r-- 1 root root 151 5月14 09:11 rand.c

-rw-r--r-- 1 root root 101 5月14 09:11 sprintf.c

-rw-r--r-- 1 root root 131 5月14 09:11 strrchr.c

-rw-r--r-- 1 root root 1563 5月22 10:09 test

-rw-r--r-- 1 root root 1471488 5月 3 16:10 unpv12e.tar

-rw-r--r-- 1 root root 142 5月14 09:11 wenjian.c

[root@localhost kk]#

本例使用指令“rm -f f*”,删除所有以字母f打头的文件。

【相关指令】

chattr、shred

◆◆

评论读取中....

请登录后再发表评论!

◆◆

修改失败,请稍后尝试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值