【问题标题】:To delete only files that has at least one digit in its file name not directories仅删除文件名中至少包含一位数字的文件而不是目录
【发布时间】:2018-08-16 09:52:19
【问题描述】:

我知道如何只删除文件而不是目录,如下所示:

find /path/to/directory -maxdepth 1 -type f -exec rm -iv {} \;

上面的sn-p是从Here那里学到的

如果我想删除文件名中至少包含一位数字的文件。

find /path/to/directory -maxdepth 1 -type f -exec rm -iv *[0-9]* {} \;

这适用于我的情况吗?有什么建议吗?

【问题讨论】:

  • 欢迎来到 StackOverflow!请注意,您的问题实际上与编程无关,而更像是关于 Linux。我建议在unix.stackexchange.com 上重新发布您的问题。

标签: linux shell ubuntu


【解决方案1】:

您可以在 -name 选项中使用 glob 模式,然后使用 -delete 选项:

find /path/to/directory -maxdepth 1 -type f -name '*[0-9]*' -delete

如果-delete 不可用,则:

find /path/to/directory -maxdepth 1 -type f -name '*[0-9]*' -exec rm -iv {} \;
猜你喜欢
  • 2011-12-04
  • 2011-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 2014-07-11
  • 2023-03-27
相关资源
最近更新 更多