linux - 仅删除文件名中至少有一位数字的文件而不是目录

标签 linux shell ubuntu

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

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

我从 Here 中学到了上面的代码片段

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

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

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

最佳答案

您可以在 -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 {} \;

关于linux - 仅删除文件名中至少有一位数字的文件而不是目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51874239/

相关文章:

linux - 有没有办法为 X 中生成的应用程序指定窗口偏移量?

python - 无法将python pip安装到docker容器

node.js - 在 ExpressJS/NodeJS 中移动文件

linux - 为什么 Ubuntu 和 VM 上的 tar 文件大小不同?

python - Ansible - When 语句使用变量

linux - fs 网络摄像头 : Unable to load font 'luxisr' : libgd was not built with FreeType font support

python - 写入文件时出现 UnicodeEncodeError

json - 将 JSON 导出到环境变量

bash - 在 shell 中使用循环使用 cat 编写多行

windows - VIM "!"和 Windows 启动命令