rm (remove) 删除,可以删除文件和目录
删除文件
先用 tree 命令查看结构,然后使用 rm 命令删除,删除时候会有提示,输入 y/n 回车后即删除
[root@evan-01 evanlinux]# ll
总用量 4
-rw-r--r-- 1 root root 15 8月 8 10:05 test.txt
[root@evan-01 evanlinux]# rm test.txt
rm:是否删除普通文件 "test.txt"?y
[root@evan-01 evanlinux]# ll
总用量 0
[root@evan-01 evanlinux]#
添加多个文件,删除文件夹下所有文件
rm *.txt 中 * 是通配符,意思要删除 /tmp/evanlinux/ 目录下的所有 .txt 文件
经常询问是否删除普通空文件,如果我们有一两个文件询问还好,如果要几十上百那就让人崩溃了,那么能不能强制删除,不提示呢?当然可以
[root@evan-01 evanlinux]# touch test1.txt
[root@evan-01 evanlinux]# touch test2.txt
[root@evan-01 evanlinux]# touch test3.txt
[root@evan-01 evanlinux]# ll
总用量 0
-rw-r--r-- 1 root root 0 8月 8 10:06 test1.txt
-rw-r--r-- 1 root root 0 8月 8 10:06 test2.txt
-rw-r--r-- 1 root root 0 8月 8 10:06 test3.txt
[root@evan-01 evanlinux]# rm *.txt
rm:是否删除普通空文件 "test1.txt"?y
rm:是否删除普通空文件 "test2.txt"?y
rm:是否删除普通空文件 "test3.txt"?y
[root@evan-01 evanlinux]# ll
总用量 0
[root@evan-01 evanlinux]#
rm -f 强制删除
[root@evan-01 evanlinux]# touch test1.txt
[root@evan-01 evanlinux]# touch test2.txt
[root@evan-01 evanlinux]# touch test3.txt
[root@evan-01 evanlinux]# ll
总用量 0
-rw-r--r-- 1 root root 0 8月 8 10:08 test1.txt
-rw-r--r-- 1 root root 0 8月 8 10:08 test2.txt
-rw-r--r-- 1 root root 0 8月 8 10:08 test3.txt
[root@evan-01 evanlinux]# rm -f *.txt
[root@evan-01 evanlinux]# ll
总用量 0
[root@evan-01 evanlinux]#
!命令 查看历史里面最近一次使用的命令
!touch 查看历史里面最近一次使用touch的命令
[root@evan-01 evanlinux]# touch test1.txt
[root@evan-01 evanlinux]# touch test2.txt
[root@evan-01 evanlinux]# touch test3.txt
[root@evan-01 evanlinux]# ll
总用量 0
-rw-r--r-- 1 root root 0 8月 8 10:08 test1.txt
-rw-r--r-- 1 root root 0 8月 8 10:08 test2.txt
-rw-r--r-- 1 root root 0 8月 8 10:08 test3.txt
[root@evan-01 evanlinux]# rm -f *.txt
[root@evan-01 evanlinux]# ll
总用量 0
[root@evan-01 evanlinux]# !touch
touch test3.txt
[root@evan-01 evanlinux]#
history 查看历史命令
[root@evan-01 evanlinux]# history
....(省略若干行)
3904 2019/08/08 10:08:26 touch test1.txt
3905 2019/08/08 10:08:27 touch test2.txt
3906 2019/08/08 10:08:30 touch test3.txt
3907 2019/08/08 10:08:31 ll
3908 2019/08/08 10:08:45 rm -f *.txt
3909 2019/08/08 10:08:47 ll
3910 2019/08/08 10:10:26 touch test3.txt
3911 2019/08/08 10:12:11 history
删除目录
反复输入y回车,过于麻烦
[root@evan-01 evanlinux]# ll
总用量 0
[root@evan-01 evanlinux]# mkdir -p one/two
[root@evan-01 evanlinux]# touch one/two/test.txt
[root@evan-01 evanlinux]# tree ./
./
└── one
└── two
└── test.txt
2 directories, 1 file
[root@evan-01 evanlinux]# rm -r one/two/
rm:是否进入目录"one/two/"? y
rm:是否删除普通空文件 "one/two/test.txt"?y
rm:是否删除目录 "one/two/"?y
[root@evan-01 evanlinux]# ll
总用量 0
drwxr-xr-x 2 root root 6 8月 8 10:15 one
[root@evan-01 evanlinux]#
强制删除目录
[root@evan-01 evanlinux]# ll
总用量 0
drwxr-xr-x 2 root root 6 8月 8 10:15 one
[root@evan-01 evanlinux]# rm -rf one/
[root@evan-01 evanlinux]# ll
总用量 0
[root@evan-01 evanlinux]#
可视强制删除目录
文件刚才都删除掉了,在这再重新创建一些,然后使用 -rvf 强制可视删除
[root@evan-01 evanlinux]# ll
总用量 0
[root@evan-01 evanlinux]# mkdir -p one/two
[root@evan-01 evanlinux]# touch one/two/test.txt
[root@evan-01 evanlinux]# tree ./
./
└── one
└── two
└── test.txt
2 directories, 1 file
[root@evan-01 evanlinux]# rm -rvf one/two/
已删除"one/two/test.txt"
已删除目录:"one/two/"
[root@evan-01 evanlinux]# ll
总用量 0
drwxr-xr-x 2 root root 6 8月 8 10:17 one
[root@evan-01 evanlinux]#