Using the tar command on Linux to uncompress tar.gz files with the command line.

Posted: February 18, 2014. At: 12:44 PM. This was 4 years ago. Post ID: 6983

The tar command on Linux is very useful for uncompressing files on your Linux machine. The most used command on a Linux system is uncompressing files that you have downloaded from an Internet source.

The tar -xvf command will uncompress a tar.gz file.

~$ tar -xvf myfile.tar.gz

To uncompress a tar.bz2 file use this command.

~$ tar -jxvf myfile.tar.bz2

Here is an example.

mint@mint ~/Downloads $ tar -jxvf libdvdcss-1.2.13.tar.bz2 
libdvdcss-1.2.13/
libdvdcss-1.2.13/src/
libdvdcss-1.2.13/src/dvdcss/
libdvdcss-1.2.13/src/dvdcss/dvdcss.h
libdvdcss-1.2.13/src/libdvdcss.pc.in
libdvdcss-1.2.13/src/device.c
libdvdcss-1.2.13/src/error.c
libdvdcss-1.2.13/src/ioctl.h
libdvdcss-1.2.13/src/device.h
libdvdcss-1.2.13/src/css.h
libdvdcss-1.2.13/src/common.h
libdvdcss-1.2.13/src/csstables.h
libdvdcss-1.2.13/src/ioctl.c
libdvdcss-1.2.13/src/libdvdcss.c
libdvdcss-1.2.13/src/libdvdcss.h
libdvdcss-1.2.13/src/css.c
libdvdcss-1.2.13/README
libdvdcss-1.2.13/aclocal.m4
libdvdcss-1.2.13/configure
libdvdcss-1.2.13/config.h.in
libdvdcss-1.2.13/depcomp
libdvdcss-1.2.13/test/
libdvdcss-1.2.13/test/dvd_region.c
libdvdcss-1.2.13/test/csstest.c
libdvdcss-1.2.13/config.sub
libdvdcss-1.2.13/config.guess
libdvdcss-1.2.13/AUTHORS
libdvdcss-1.2.13/libdvdcss.spec
libdvdcss-1.2.13/NEWS
libdvdcss-1.2.13/Makefile.am
libdvdcss-1.2.13/doc/
libdvdcss-1.2.13/doc/doxygen.cfg.in
libdvdcss-1.2.13/doc/footer.html
libdvdcss-1.2.13/doc/header.html
libdvdcss-1.2.13/COPYING
libdvdcss-1.2.13/INSTALL
libdvdcss-1.2.13/configure.ac
libdvdcss-1.2.13/ChangeLog
libdvdcss-1.2.13/missing
libdvdcss-1.2.13/m4/
libdvdcss-1.2.13/m4/ltsugar.m4
libdvdcss-1.2.13/m4/lt~obsolete.m4
libdvdcss-1.2.13/m4/libtool.m4
libdvdcss-1.2.13/m4/attributes.m4
libdvdcss-1.2.13/m4/ltversion.m4
libdvdcss-1.2.13/m4/ltoptions.m4
libdvdcss-1.2.13/install-sh
libdvdcss-1.2.13/ltmain.sh
libdvdcss-1.2.13/Makefile.in
libdvdcss-1.2.13/msvc/
libdvdcss-1.2.13/msvc/libdvdcss.dsp
libdvdcss-1.2.13/msvc/workspace.dsw
libdvdcss-1.2.13/msvc/csstest.dsp
libdvdcss-1.2.13/msvc/config.h

To create a tar.gz archive of a directory and its contents, use this command: tar -zcvf archive.tar.gz dir/

mint@mint ~/Downloads $ tar -zcvf mine.tar.gz mine/
mine/
mine/mylist.txt
mine/my.txt

To uncompress to a specific directory, use the uncompress command with the -C parameter. Here I am uncompressing the archive to /tmp.

mint@mint ~/Downloads $ tar -xvf mine.tar.gz -C /tmp/
mine/
mine/mylist.txt
mine/my.txt

To list the contents of a tar.gz file; use this command.

mint@mint ~/Downloads $ tar -tvf mine.tar.gz
drwxr-xr-x mint/mint         0 2014-02-18 01:24 mine/
-rw-r--r-- mint/mint      8552 2014-02-18 01:24 mine/mylist.txt
-rw-r--r-- mint/mint         0 2014-02-18 01:24 mine/my.txt

For a tar.bz2 file; you would use this command.

mint@mint ~/Downloads $ tar -jtvf mine.tar.bz2
drwxr-xr-x mint/mint         0 2014-02-18 01:24 mine/
-rw-r--r-- mint/mint      8552 2014-02-18 01:24 mine/mylist.txt
-rw-r--r-- mint/mint         0 2014-02-18 01:24 mine/my.txt

No comments have been made. Use this form to start the conversation :)

Leave a Reply