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

删除文件时排除特定文件

www.python  tab.com/html/2013/linuxkaiyuan_0205/214.html

 

 

 

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

1
2
3
4
5
6
7
8
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)'`

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

 

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

posted on 2017-04-11 19:15  studyphp  阅读(18311)  评论(1编辑  收藏  举报

导航