rm命令排除某一个或多个文件和文件夹的删除
后来我有看了bash shell编程的文档,发现在打开extglob模式下(缺省是打开的),ls也可以实现,而且更加灵活.1.先确认extglob模式已经开启
#shopt extglob
如果是off,用下面命令开启extglob模式
# shopt -s extglob #打开
# shopt -u extglob #关闭
2.新建几个文件和文件夹进行测试
#touch main.c main.h hello.c hello.h
#mkdir dir1 dir2
保留hello.c hello.h dir1
#rm -rf !(hello.c|hello.h|dir1)
感叹号后不能有空格。
页:
[1]