rm命令删除文件时排除特定文件

rm -rf `ls  |egrep -v bb` 删除所有,保留bb 目录

注意:上面所用的符号是‘`’,而不是单引号

删除当前目录下所有 *.txt文件,除了test.txt

rm `ls *.txt|egrep -v test.txt`
#或者
rm `ls *.txt|awk '{if($0 != "test.txt") print $0}'`
#排除多个文件
rm `ls *.txt|egrep -v '(test.txt|fff.txt|ppp.txt)'`
rm -f `ls *.log.1|egrep -v '(access-2010-09-06.log|error-2010-09-06.log)'`
rm -f `ls *.log|egrep -v '(access-2010-09-06.log|error-2010-09-06.log)'`
rm -f `ls *.log|egrep -v '(20100906.log)'`

  

https://www.cnblogs.com/already/p/6695031.html

原文地址:https://www.cnblogs.com/achengmu/p/11856747.html