2

我想删除所有名称如下的文件:*~ or #*#.
我努力了:

find "dir" -name '#*#' -or -name '*~' -delete

但它只删除末尾带有 ~ 的文件,而不是开头和结尾带有 # 的文件

我怎样才能做到这一点?

4

3 回答 3

1

First, you need to specify a pattern with the -name primary; ## would match a file named exactly ##, while *## would match any file that ends with ##. Second, you need to group the two uses of name so that either one matching will count as a match to be deleted.

find dir \( -name '*##' -or -name '*~' \) -delete
于 2013-07-15T17:39:10.103 回答
0

How about find with -regex switch:

find -E . -regex "^./(~|##)$" -exec rm '{}' \;

-E is being used to support extended (modern) regular expression feature.

于 2013-07-15T17:33:42.427 回答
0

我找到了我的解决方案:find dir -name " ~" -delete -or -name "# #" -delete 谢谢大家

于 2013-07-16T12:06:44.913 回答