禁止使用rm命令与删除filename之外的文件

1、使用rm命令时提示Do not use rm command

alias rm='echo Do not use rm command'

使rm提示生效 /etc/profile。 . /etc/profile或者 source /etc/profile

vim /etc/profile(先执行)

vim /etc/bashrc (后执行)

后执行的掩盖先执行的命令。所以只要修改~/.bashrc

2删除filename之外的文件

[root@localhost QQ]# touch 1.txt 2.txt 3.txt 4.txt
[root@localhost QQ]# ls
1.txt 2.txt 3.txt 4.txt

删除4.txt之外的文件。

第一种方法:

[root@localhost QQ]# ls |grep -v "4.txt"|xargs rm -f
[root@localhost QQ]# ls
4.txt

第二种方法:

[root@localhost QQ]# find ./ -type f ! -name "3.txt"|xargs rm -f
[root@localhost QQ]# ls
3.txt

原文地址:https://www.cnblogs.com/xusx/p/6040321.html