删除文件时排除特定文件 (转载)

  转自:http://blog.csdn.net/catoop/article/details/8548292

 

删除文件时排除特定文件
删除当前目录下所有 *.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)'`
---------------
这里是用ls得到原始数据,也可以用find命令
rm `find . -name *.txt | egrep -v ‘(test.txt|fff.txt|ppp.txt)'`

posted on 2016-07-29 10:31  次奥砖家  阅读(281)  评论(0编辑  收藏  举报

导航