简体   繁体   English

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

[英]Using find command on in a Bash Script to find integers

I need to find and archive files with a certain file name eg ABC_000.jpg 我需要查找和存档具有特定文件名的文件,例如ABC_000.jpg

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

however I can not seem to find a way to limit the find function to find only 3 integers as there are files that are named ABC_CBA.jpg that I do not want included 但是我似乎无法找到一种方法来限制find函数只能找到3个整数,因为有些文件名为ABC_CBA.jpg我不想包括

Try this find: 试试这个:

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

EDIT: Or using regex: 编辑:或使用正则表达式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM