我想删除所有名称如下的文件:*~ or #*#
.
我努力了:
find "dir" -name '#*#' -or -name '*~' -delete
但它只删除末尾带有 ~ 的文件,而不是开头和结尾带有 # 的文件
我怎样才能做到这一点?
我想删除所有名称如下的文件:*~ or #*#
.
我努力了:
find "dir" -name '#*#' -or -name '*~' -delete
但它只删除末尾带有 ~ 的文件,而不是开头和结尾带有 # 的文件
我怎样才能做到这一点?
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
How about find with -regex
switch:
find -E . -regex "^./(~|##)$" -exec rm '{}' \;
-E
is being used to support extended (modern) regular expression feature.
我找到了我的解决方案:find dir -name " ~" -delete -or -name "# #" -delete 谢谢大家