您的位置:首页 > 编程语言 > Go语言

删除当前目录下所有符合某些patterns的文件

2018-04-12 04:40 417 查看
File: rmall.sh

Usage: rmall.sh [-t] pattern1 [pattern2] ...

Script type: bash

-t 仅测试而不真正删除,打印所有将要删除的文件列表

 

Samples: remove temporary files ended with '~'

rmall.sh -t '*~'

rmall.sh '*~'

 

另一个更有效的方法可能是用find的logical OR操作来寻找符合多个patterns中任意一个的文件,比如

find . /( -name /*foo/* -o -name /*bar/* /)

不过我在这里没用,分别处理每一个pattern对于我来说看得更清楚。

 

#!/bin/bash
if test $# -eq 0
then
echo 'Usage: rmall [-t] patterns'
exit 1
fi
if test $1 = '-t'
then
shift
for fname in $*; do
echo removing file pattern $fname
find . -name $fname -exec ls -lh '{}' /;
echo ''
done
else
for fname in $*; do
echo removing file pattern $fname
find . -name $fname -exec echo '{}' /; -exec rm '{}' /;
echo ''
done
fi


Youdao-DicticibaWikipediaWictionaryChambers (UK)Google imagesGoogle defineThe Free DictionaryJoin exampleWordNetGoogleAnswers.comrhymezone.comMerriam-Webster<
>
0

y
b
w
v
c
i
d
f
j
o
g
a
r
m
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  file google 测试
相关文章推荐