How to automatically unpack a set of files compressed in bz2 in Ubuntu 16.04

123 Views Asked by At

I have many files (.bz2) inside the same directory in a Ubuntu 16.04 machine. I can manually unpack each one of the files by using bzip2 -dk filename.bz2 but I assume there is a way to do this automatically since they are many files.

1

There are 1 best solutions below

1
Arduino_Sentinel On BEST ANSWER

if all files are in single directory,

You can do bzip2 -d -k *.bz2 where -d means decompress as bzip2 by default is for compression and -k means keep the input files and *.bz2 tells bzip2 to search for every single file ending with .bz2 extension to be extracted.
Also you can use bunzip2 -k *.bz2 as bunzip2 by default is for decompression so no need for -d command.

if you prefer bash scripting, You can also use a forloop

for b in *.bz2; do bunzip2 $b; done