Unable to use tar to run an archive through bzip2 compression
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:
- 3.2. Using bzip2 with tar
- Compression support
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
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.