Extract Files from Archived Tarballs at the Terminal in Linux

Extract Files from Archived Tarballs at the Terminal in Linux

Modern tar recognizes the format by itself! One command works with any supported compression method.

$ tar xf archive.tar.xz
$ tar xf archive.tar.gz

$ tar xf archive.tar.bz2

$ tar xf archive.tar

Adding a v will make the output verbose (ex: tar xvf or tar xfv actually the order doesnt really matter)

(Legacy Support: For the older versions for tar.gz its $ tar xvfz somefilename.tar.gz but still applicable though like it mentions above xf is enough in most cases)

For the Bunzip2 or bzip2 or bz2 or tar.bz2 file in a single step, add the j switch:

$ tar xfj somefilename.tar.bz2 or $ tar xvfj somefilename.tar.bz2

Take not that its using a lowercase j as a capital J is for a different option switch as mentioned below

$ tar -xJf file.pkg.tar.xz

(The -J is the flag that specifically deals with .xz files.)

(For basic unzipping)
$ unzip file.zip


(to extract to a certain directory)

$ unzip file.zip -d destination_directory/

In 7zip:

This command lists the contents of the zip:
$ 7z l zipfile.zip

This command extracts the contents of the zip:
$ 7z x zipfile.zip

To unrar, within the directory (the e option extracts):
$ unrar e foo_file.rar

To unrar to a specified directory:
$ unrar e foo_file.rar destination_directory/

To unrar with its own original directory structure
$ unrar x foo_file.rar


Post a Comment