0

So I have an array with some names. I need to find all the files in another folder with a certain pattern and copy those files over to my current folder.

NAME=(JOHN)
for i in ${NAMES[@]}
do
   cp ~/folder/$i .
done
0

You could use find:

find /yourdir -name '*JOHN*' -exec cp {} ~/folder/  \;

Related question on SO.

| improve this answer | |
0

Try with this one, If your filename is of specified pattern:

NAME=(PATTERN1 PATTERN2)
for i in ${NAMES[@]}
do
   find PATH -name "$i" -exec cp -av {} PATH_TO_COPY \;
done 

If your filename have other string other than PATTERN:

NAME=(PATTERN1 PATTERN2)
for i in ${NAMES[@]}
    do
       find PATH -name "*${i}*" -exec cp -av {} PATH_TO_COPY \;
    done 

make changes as per your need.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.