排除删除文件或者文件夹
1,必须要确保开启 extglob
shopt extglob
开启和关闭命令:
shopt -s extglob
# -s 开启, -u 关闭
2.新建几个文件和文件夹进行测试
touch {1..10}.txt
touch main.c main.h hello.c hello.h
mkdir dir1 dir2
3.保留hello.c hello.h dir1
rm -rf !(hello.c|hello.h|dir1)
rm -rf !(kx*) #保留所有kx开头的文件和文件夹
- 删除当前目录所有文件
rm -rf *