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)'`