问题描述
我有一个名为的文件列表:
I have a list of files named:
文件000
file001
file002
file003
...
file1100
file000
file001
file002
file003
...
file1100
如何匹配数字大于800但小于1000的所有文件?我正在使用linux bash
How can I match all files that have a number greater than 800 but less than 1000 ?I am using linux bash
谢谢
实际上,我的文件命名为:
ab869.enc
cp936.enc
g122345.enc
x2022.enc
abc8859-14.enc
aax5601.enc
cp936-1.enc
Actually, my files are named like:
ab869.enc
cp936.enc
g122345.enc
x2022.enc
abc8859-14.enc
aax5601.enc
cp936-1.enc
所以第一个解决方案与正确的文件不匹配:(
so the first solution dont match the correct files :(
如何匹配编号在800-999之间的文件?
How can I match files that have number between 800-999 ?
推荐答案
*[89][0-9][0-9].enc
它使用Bash的路径名扩展"功能(也称为"globbing")来匹配所有以800到999之间的数字后接".enc"的文件. (这不是正则表达式).
That uses Bash's "pathname expansion" feature (aka "globbing") to match all files ending with a number between 800 and 999 followed by ".enc". (This is not a regular expression).
例如,使用上面的表达式,您可以在脚本中执行以下操作:
For example, using the above expression you can do this in your script:
mv *[89][0-9][0-9].enc path/to/destination/
如果需要它还与名为"cp850-1.enc"的文件匹配,则需要将表达式更改为:
If you need it to also match a file named like "cp850-1.enc", then you would need to change the expression to:
*[89][0-9][0-9]*.enc
这篇关于Linux文件名文件遍历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!