重击括号扩展:如何用数字匹配所有文件名? [英] Bash bracket expansion: How to match all files names with a number?

查看:47
本文介绍了重击括号扩展:如何用数字匹配所有文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要匹配目录中的所有文件名,如下所示:

I want to match all filenames in a directory that are like this:

h1.txt, h2.txt, h12.txt, h3.txt

如果我愿意

echo h[[:digit:]].txt

我知道

h1.txt, h2.txt, h3.txt

因此它匹配我想要的所有文件,但 h12.txt 除外,因为它有两位数字而不是一位数字.一个或多个数字是否可以扩展?

so it matches all the files I want, except h12.txt, because it has two digits instead of one. Is there an expansion for one or more digits?

推荐答案

想通了!

echo h+([[:digit:]]).txt

这篇关于重击括号扩展:如何用数字匹配所有文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆