How do I tar bzip2 a directory in Linux?
One of the better compressions is bzip2, and in one easy command you can compress a directory to .tar.bz2. I’ll show you how!
Simply do the below command. Here I’m compressing a directory called ‘stuff’.
(Though not required, I suggest using the option ‘p’ which will preserve file permissions.)
tar jcvpf stuff.tar.bz2 stuff/
To extract that, just issue this command:
tar jxvf stuff.tar.bz2
Or, specify where to extract that archive if needed:
tar jxvf stuff.tar.bz2 -C /extract/over/here
tar is NOT multi-threaded. :/ It is painful to watch tar use only one of your available CPUs, especially if you do the cpu-intensive bzip2 compression.
However if you find yourself needing to do this often, use pbzip2 which IS multi-threaded.