I am having difficulty compression an archive with bzip using tar. The archive I have is user-logs.tar.

I am attempting to run this:

tar -jf user-logs.tar

I get this error:

tar: You must specify one of the `-Acdtrux' or `--test-label'  options
Try `tar --help' or `tar --usage' for more information.

I also attempted using -c to create a new file with the bzip filename extension with no luck.

# tar -cvjf user-logs.tar.gz user-logs.tar
tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
  • To compress user-logs.tar, do bzip -9 user-logs.tar. To package and compress tar jcf user-logs.tar.bz2 file file file...
    – vonbrand
    Feb 24 '16 at 22:47

The error message tells what to do: you probably need to add -c (for create), e.g.,

tar -jcf user-logs.tar  myargs

as well as some arguments myargs (things to put into the user-logs.tar archive).

In the second case, the problem is that you do not have bzip2 installed. The tar program relies upon this external program to do compression.

If you have a tar archive and simply want to compress it, you could do this:

bzip2 user-logs.tar

which (if you had bzip2 installed) would change the file to user-logs.tar.bz2 (and usually make it much smaller).

For installing bzip2, it depends on the system you are using. For example, with Ubuntu that would be

sudo apt-get install bzip2

while Fedora might be (perhaps dnf):

sudo yum install bzip2

The GNU tar program does not know how to compress an existing file such as user-logs.tar (bzip2 does that). The tar program can use external compression programs gzip, bzip2, xz by opening a pipe to those programs, sending a tar archive via the pipe to the compression utility, which compresses the data which it reads from tar and writes the result to the filename which the tar program specifies.

Alternatively, the tar and compression utility could be the same program. BSD tar does its compression using libarchive (they're not really distinct except in name).

Further reading:

  • I didnt know it relied on the external bzip thank you. But, what If i dont want to add anything to the archive. I just want to compress the archive that already exists with bzip2
    – Oscalation
    Feb 24 '16 at 2:23
  • For that, you need the external bzip2 program. Feb 24 '16 at 2:25
  • I think my confusion was this, tell me if this is correct, once a archive (file.tar) is created, you cant compress it with the tar utility. Tar will compress and archive at the same time. Is that right?
    – Oscalation
    Feb 24 '16 at 17:04

I'm not sure I interpret your question and data correctly, but it looks to me as if you already have the tar ball and just want it compressed?

bzip2 user-logs.tar
  • yes that is correct
    – Oscalation
    Feb 24 '16 at 2:21
  • @Oscalation : OK, so my "solution" above is correct. Next time just create your tarball w/ the appropriate switch: tar cvzf user-logs.tbz2 /path/to/logs
    – tink
    Feb 24 '16 at 2:30
  • 1
    @tink: the z option is for compressing with gzip; you probably wanted to say j for the bzip2 compression
    – user22304
    Feb 24 '16 at 13:14
  • @FrancescoTurco: that's correct.
    – tink
    Feb 24 '16 at 18:01

Error message bzip2: Cannot exec: No such file or directory tells you that tar can't find bzip2. Most likely you don't have it installed.

Install it via yum install bzip2 or apt-get install bzip2 or something like that, depending on your OS.

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.