0

I'm trying to write a script to zip particular files with specific suffixes and different file types in a directory. I see posts about zipping all files of particular extensions, but am hung up about how to only get certain files that have particular suffixes.

Here is an example contents of directory:

MCI_1003_4_FaMap.hdr   the MCI_1003_4_RefB0.dat   MCI_1003_4_Tensor.img
MCI_1003_4_ColorMap0.hdr  MCI_1003_4_EgVec0.dat  MCI_1003_4_FaMap.img    MCI_1003_4_RefB0.hdr   MCI_1003_4_Trace.dat
MCI_1003_4_ColorMap0.img  MCI_1003_4_EgVec0.hdr  MCI_1003_4_MeanDwi.dat  MCI_1003_4_RefB0.img  MCI_1003_4_EgVal0.dat     MCI_1003_4_EgVec0.img  MCI_1003_4_MeanDwi.hdr  MCI_1003_4_Tensor.dat  
    MCI_1003_4_FaMap.dat   MCI_1003_4_MeanDwi.img  MCI_1003_4_Tensor.hdr

I just want the following files to zip into something like DTI.zip

MCI_1003_4_MeanDwi.hdr 
MCI_1003_4_MeanDwi.img
MCI_1003_4_Trace.dat
MCI_1003_4_RefB0.hdr
MCI_1003_4_RefB0.img

This is my unsuccessful attempt at a for loop:

for i in * ; do zip -r "DTI.zip" "*RefB0.hdr" "*RefB0.img "*Tensor.dat" "*MeanDwi.hdr" "*MeanDwi.img" $i; done
3

Why not just:

zip DTI.zip *RefB0.hdr *RefB0.img *Trace.dat *MeanDwi.hdr *MeanDwi.img

No for loop or quoting necessary.

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.