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

时间:2013-11-20 14:35:15

标签: linux bash find

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

find ~/my-documents/ -iname "ABC_***.JPG" -type f -exec cp {} ~/my-documents/archive/ \;

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

1 个答案:

答案 0 :(得分:6)

试试这个:

find ~/my-documents/ -iname "ABC_[0-9][0-9][0-9].JPG" -type f -exec cp '{}' ~/my-documents/archive/ \;

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

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