Compress a tar file to smaller size

I have a tar file with name DTT012_GP_20140207.tar and many more with different names of different sizes ranging from 1GB to 4GB.
Now my requirement is to extract/not extract these files and then divide it into various parts of size 500MB and save it with different names and then compress it(zip/tar).
(If 1GB tar file, it should divide into 2 500MB,
If 1.6GB file, it should divide into 2 500MB and the remanning 100MB into another)

I have tried this

split -b 500000000 DTT012_GP_20140207.tar /tmp/newdata/DTT012_GP_20140207_part.tar

The output files generated come with name DTT012_GP_20140207_part.tara , DTT012_GP_20140207_part.tarb , DTT012_GP_20140207_part.tarc

Please let me know if I am doing it right and also how do i name it in increasing order as part1,part2,part3??

tar (tape archive) by default does not compress files. It merely manipulates files in an archive.

1 Like

If it was me, and if I understand you correctly, I would simply untar ( tar -xvf ) the original file (or tar -xvzf if gzipped), and then split it into multiple parts and then tar them up again and recompress ( tar -cvzf )

Neo:

Thanks.
But will that serve the purpose??
I want the files from the 1GB tar file (data.tar- untarred to data) to be copied into two separate folders as data_part1 and data_part2 and then recompress these two folders.

Contents inside the tar file are more file1.gz,file2.gz,file3.gz... and so on..

file1.gz,file2.gz (assuming it to be less than or equal to 500MB) should be copied to file1 and then compress to data_part1.zip and then remaining files(file3.gz,file4.gz...) assuming them to total another 500MB and copy to data_part2 and then compress to data_part.zip

Can you or any other Unix expert help me with that??

Well, your second post describes quite a different problem than your first post.

What script have you written?

Our amazing members are not here to write your scripts for you, but to assist you in your (best) efforts to define your problem and write your own scripts.

Neo:

Firstly, my apologies. I dint mean to ask experts here to write a script for me for the above post.

I thought it was a one line thing required.

Anyways, I am trying what i have already mentioned.

split -b 500000000 DTT012_GP_20140207.tar /tmp/newdata/DTT012_GP_20140207.tar

But with some help around, i tried the below modification,

split -b 500000000 DTT012_GP_20140207.tar  /tmp/newdata/DTT012_GP_20140207.tar_part_

Output:

DTT012_GP_20140207.tar_part_aa
DTT012_GP_20140207.tar_part_ab
DTT012_GP_20140207.tar_part_ac

Also, i forgot to mention that once I have split the particular file.tar, I have to resume it as well for which I am using the below.

cat DTT012_GP_20140207.tar_part_* | tar xzpvf -

Output:

DTT012_GP_20140207.tar

#Update-It is working fine now.

Thanks a lot Neo.

1 Like