在Bash脚本中使用find命令来查找整数

Whe*_*tax 3 linux bash find

我需要查找和存档具有特定文件名的文件,例如ABC_000.jpg

find ~/my-documents/ -iname "ABC_***.JPG" -type f -exec cp {} ~/my-documents/archive/ \;
Run Code Online (Sandbox Code Playgroud)

但是我似乎无法找到一种方法来限制find函数只能找到3个整数,因为有些文件名为ABC_CBA.jpg我不想包括

anu*_*ava 6

试试这个:

find ~/my-documents/ -iname "ABC_[0-9][0-9][0-9].JPG" -type f -exec cp '{}' ~/my-documents/archive/ \;
Run Code Online (Sandbox Code Playgroud)

编辑:或使用正则表达式:

find -E ~/my-documents/ -iregex ".*ABC_[0-9]{3}\.JPG" -type f -exec cp '{}' ~/my-documents/archive/ \;
Run Code Online (Sandbox Code Playgroud)