Bzip2 — a file compression algorithm, often used in conjunction with tar. The fact that he does not know how tar to reduce the weight of the archive — this program only compresses files and folders uncompressed.
After that, the action takes bzip2, compressing the finished file to a *.tar and assigning it the name *.tar.bz2 or *.tbz2. In this article we will tell you to unzip bz2 linux using the tar command.
How to unzip bz2 in Linux
1. The usual unpacking bz2
In most distributions of Linux tar utility installed out of the box. Therefore, to extract files from a tar archive.bz2 just open a terminal and enter the command tar use –extract (abbreviated to x), which directly indicates the effect from the archive, and -f, followed by the name of the archive. In some cases, you may need sudo at the beginning of the row.
tar -x -j-f archive.tar.bz2
If for any reason the terminal impossible to use the capabilities of the file Manager — move the cursor to the file you want to extract, right-click on mouse and select Extract or extract to current folder.
To see what files have been extracted, would need to use -v, and line in terminal would look like this:
By default, tar extracts files in the current directory (usually this is your home folder). To assign a different location where will be placed the contents of the archive, use the option -C (–directory). For example, for the directory /user/losst/new-folder entry should be:
tar-xjf archive.tar.bz2 -C /home/losst/new-folder
2. Select files to unpack
If you want to extract from the archive specific files, not unpacking it, should be the name of the archive to list the names of these files separated by a space:
tar-xjf archive.tar.bz2 file1 file2
When inside the archive contains folders and the required files are located within them, have to specify not only the names but also the full path to the file. To view the structure of the archive with the option –list (-t) — how to do it will be discussed below.
Removing certain folders occurs in a similar way:
tar-xjf archive.tar.bz2 dir1 dir2
While trying to retrieve a file that is not in the archive, you will see the error message.
To retrieve a group of files, names of which include the same element, there is the option –wild cards. A group wildcard is the asterisk, and the template should highlight the quotation marks. Here is an example for retrieving documents that have the extension odt:
tar-jf archive.tar.bz2 --wild cards are '*.odt'
3. Unpacking in the stream
Extracting compressed files from the tar.bz2 using stdin you need to specify the-j option. It indicates that the file has been compressed it bz2.
In this example, the source Vim files are downloaded with the command wget followed by the tar command:
wget-c ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2 -O - | sudo tar xj
If option -j is specified, tar will report this and point the way to correct a mistake about as tar: Archive is compressed. Use-j option.
4. View the structure of the archive
To view the structure of the archive tar bz2 linux is an option –list (-t):
If you add the option –verbose (-v)option, tar will show more information about files:
Tar gives a huge range of possibilities to unpack archives tar.bz2. We tried to tell them as much detail as possible, but if you have any difficulties with using tar in the terminal, ask your questions in the comments.