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

禁用rm命令与文件删除技巧
本文介绍如何在Linux系统中禁用rm命令并使其显示特定警告信息的方法,同时分享了两种实用的文件删除技巧。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值