2

How do I convert .tar.gz and .tar.bz2 files to .7z files using the command line?

4
  • 3
    You might be able to edit this script converting from zip to fit your demands? Also there is an online converter supporting the mentioned formats.
    – N.N.
    Commented Jun 26, 2011 at 8:52
  • @N.N.: Thanks for the link... it seems to be what I want, aside from the fact that it requires a temporary directory (which is nontrivial, given that my files are big). I'll give it a try anyhow; thanks.
    – user541686
    Commented Jun 26, 2011 at 8:57
  • 1
    I'm pretty sure that you can't avoid writing the files to disk in an uncompressed form. I don't think any useful compression algorithm can do its work without having the whole file to look at.
    – Lukasa
    Commented Jun 26, 2011 at 10:05
  • Would the biggest of your files fit into memory uncompressed? If so, you might find it worthwhile to use a ramdisk for the temporary files? Commented Jan 6, 2013 at 1:57

2 Answers 2

0

Update: I missed the 'windows' tag on your question completely.
So, unless you use some unix tools (Cygwin?), this answer is not usable there.
I am expecting cygwin to implement this pipe correctly -- you'll need bash, tar, bzip2 and 7z from the environment.


You can pipe the tar output into a 7z like this,

tar xfj filename.tar.bz2 | 7z a -si filename.7z

and similarly,

tar xfz filename.tar.gz | 7z a -si filename.7z

This will save you the disk-space for extracted data -- but its not converting inline.
You will still need sufficient space to store the '7z' being created from the tarball.
You can only delete the tarball after the pipe ends.

2
  • 2
    tar xf file.tar extracts files to disk , perhaps you meant to say tar -xf file.tar -O which sends the extracted files to StdOut
    – Bor691
    Commented Nov 19, 2014 at 20:58
  • I submitted an edit to resolve the above issue (extracting to disk rather than stdout), but alas this still does not work - it compresses the tar archive as a single file within the 7z, rather than creating a 7z of the files within the tar
    – Dark
    Commented Oct 18, 2020 at 12:37
0

try ArcConvert.

i did not personally tested this program but it says it does what you want , from their site :

------------------------------------------------------------------------------
This convertor can convert the following archives:
------------------------------------------------------------------------------
7-ZIP/ LZH / CAB / ZIP / ARJ / ACE / RAR / TAR / TGZ / GZ / Z / BZ2 / YZ1 /
YZ2 / GCA / BEL / RPM / DEB/ BH / Noa32 / HKI / PAQAR / SQX /HA /ZOO /
UHARC /LFB / ZLIB / UCL / IMP / RS / SPL / APK / Arc / DZ / MSI / ALZ /
PMA / PAQ7 / CHM / UDA / PAQ8 / Cryptonite / ISO / LZOP / BMA /
ZIP AES (128/192/256) / Nanozip Alpha/ XZ/ FreeArc/Zpaq/GZA
------------------------------------------------------------------------------
to the following ones:
------------------------------------------------------------------------------
ZIP, 7-ZIP, CAB, LHA, TAR, TGZ, BZ2, YZ1, BGA, RAR, ACE, NOA32, PAQAR,
UHARC, YZ2, DZ, HA, XZ, FreeArc, ARJ/PAQ9/GZA

screenshot:

ArcConvert

1
  • The OP asked for a command line solution. Also, ArcConvert is just a GUI for various tools. Internally it uses for example 7z.exe which is a command line tool.
    – nixda
    Commented Nov 19, 2014 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .