Is there a way to extract a bzip2-archive's content into another directory without creating temporary files?


I'm working with Wikipedia XML dumps and am looking for a way to extract them directly onto my ramdisk. They are simply a single xml file compressed with bzip2.

I tried

bzip2 -dk archive.bz2 /target/directory

But this ends up extracting the contents into the same directory archive.bz2 resides in. I didn't bother to wait and see if the contents get moved afterwards, as that's not what I'm looking for. Any ideas?


Posted 2015-02-01T14:54:22.573

Reputation: 113



The samplest way I know is to do this:

cd /target/directory; bzip2 -d /path/to/achive/archive.bz2 

Romeo Ninov

Posted 2015-02-01T14:54:22.573

Reputation: 2 062

On my system, this seems to create a temporary file in the archive's directory, which I would like to avoid if possible. – Adrian – 2015-02-01T15:13:04.510

@Adrian, set TEMP variable to somewhere, for example target directory and try again. And consider bzip2 use good amount of memory when compression is high – Romeo Ninov – 2015-02-01T15:15:54.033

I tried setting TEMP=/mnt/ramdisk which is my target and then running your command from there, but I still get a temporary inside the source directory. What am I missing? – Adrian – 2015-02-01T15:22:19.533

@Adrian, this file is actually the uncompressed archive and you can't avoid it. I personally have no info how you can set to be created somewhere else. But you can always move the archive itself – Romeo Ninov – 2015-02-01T15:26:34.550

I see. I was hoping there was a way to funnel the extracted data on-the-fly to the target directory as a data stream. I'll see if I can find another solution. Thanks for the help though! – Adrian – 2015-02-01T15:29:19.877