一、使用扩展通配符
1) 开启扩展通配符
shopt -s extglob
2) 查看是否开启
shopt -s
3) 使用命令(要删除当前目录下 nodelete.txt 以外的所有文件)
rm -rf !(nodelete.txt)
二、find命令法
1) find . -not -name "nodelete.txt" -exec rm -rf {} \;
2) 也可以将find的结果通过xargs进行转换后再交给rm命令处理。
find . -not -name "1.tt" | xargs rm -rf
三、shell脚本
for i in `ls`;do if [ "$i" != nodelete.txt ];then rm -rf $i;fi;done;