0

I have a huge list of tbz files, approximately 1000 tbz, which I want to UNZIP TO dm4 files. How do I go about it one shot.

  • Wherein lies the "conversion" mentioned in the title? Are these tbz files simply bzip2-compressed tar archives? Do they contain the dm4 files? – Kusalananda Jun 20 at 15:03
  • Hello Kusal. Yes, these tbz files contain dm4s. I just wanted to unzip them all in one shot. How can I do that? – mywayz Jun 20 at 18:56
1

Using GNU tar:

for archive in *.tbz; do
    tar -x -j -f "$archive"
done

This would attempt to extract all the files matching *.tbz in the current directory. It is assumed that each such file is a bzip2-compressed tar archive.

To see the files while they are extracted, use tar with its -v option:

for archive in *.tbz; do
    tar -x -vj -f "$archive"
done

With another implementation of tar that does not implement -j for handling bzip2-compressed data, you would have to decompress the archives separately:

for archive in *.tbz; do
    bzcat "$archive" | tar -x -v -f -
done

This would obviously work with GNU tar as well. bzcat could be replaced by bzip2 -d -c.

To extract the files to another directory than the current one, use -C destdir with tar:

for archive in *.tbz; do
    tar -x -j -f "$archive" -C destdir
done

This assumes that you want to put the files into the directory called destdir in the current directory.

  • Hello Kusal, I had a question about commands above. How can I store all the extracted untapped files in a different folder instead of trying to untar in the same directory. Can you share a simple example. Thanks – mywayz Jun 20 at 20:18
  • @mywayz See the updated answer, and also the tar manual on your system. – Kusalananda Jun 20 at 20:24
  • Kusal, i have situation where all my .tbz files are in a folder which has bunch of other extension files too. How can I make sure I unzip just those tbz files from that folder to another folder. – mywayz Jun 25 at 18:35
  • @mywayz The code in my answer only tries to extract files with a .tbz filename suffix. It will not touch the other files. The last loop shows how to use the -C option of tar to extract the files to another directory (which needs to exist already). If you feel uncertain about any of this, then back up your files and test the tar command in the body of the loop on a single one of the .tbz files (replace $archive with the name of that file). – Kusalananda Jun 25 at 18:41
  • So when I give the command - tar -x -j -f "/scratch/tbz_file_drc" -C /scratch/unzipped I get the following error tar (child): /scratch/tbz_file_drc: Cannot read: Is a directory tar (child): At beginning of tape, quitting now tar (child): Error is not recoverable: exiting now bzip2: Compressed file ends unexpectedly; perhaps it is corrupted? Possible reason follows. bzip2: Inappropriate ioctl for device – mywayz Jun 25 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.