Batch Files – How to Create Separate Archives for a Set of Files

batchbatch filetar

I have directory containing big list of files.
I'd like to gzip each file of a certain mask to a separate archive.
How do i do that automatically?

For example here's sample directory contents:
– index.html
– start.html
– myfile1.txt
– myfile2.txt
– myfile3.txt

How to i create separate archive (myfile1.tar.gz,myfile2.tar.gz …) for each file starting with 'myfile*' ?

Best Answer

if you use the bash it could look like this

for file in `ls abc_*`; do tar -czvf $file.tar.gz $file ; done

you simply change the "abc_" to your beginning filename.

Be careful it will re compress the already compressed files, because they start like the normal files.

Best regards Kenny

Related Question