FreeBSD Linux

Extract Tar Files to a Different Directory

Syntax

Typical Unix tar syntax:
tar -xf file.name.tar -C /path/to/directory

GNU/tar syntax:
tar xf file.tar -C /path/to/directory

tar xf file.tar --directory /path/to/directory

Example: Extract files to another directory

In this example, I’m extracting $HOME/etc.backup.tar file to a directory called /tmp/data. First, you have to create the directory manually, enter:

 
mkdir /tmp/data

To extract a tar archive $HOME/etc.backup.tar into a /tmp/data, enter:

 
tar -xf $HOME/etc.backup.tar -C /tmp/data

To see a progress pass the -v option:

 
tar -xvf $HOME/etc.backup.tar -C /tmp/data
 

You can extract specific files too use:
 
tar -xvf $HOME/etc.backup.tar file1 file2 file3 dir1 -C /tmp/data

To extract a foo.tar.gz (.tgz extension file) tarball to /tmp/bar, enter:

 
mkdir /tmp/bar
tar -zxvf foo.tar.gz -C /tmp/bar

To extract a foo.tar.bz2 (.tbz, .tbz2 & .tb2 extension file) tarball to /tmp/bar, enter:

 
mkdir /tmp/bar
tar -jxvf foo.tar.bz2  -C /tmp/bar

Related Articles

  • Patching The Ghost Vulnerability

    The Ghost vulnerability, also known as CVE-2015-0235, is an exploit in a library named glibc. This library is referenced by many applications which run on your server. The exploit is...
  • How to get rid of ^M characters.

    When you edit a file in Windows and then open in UNIX, you must have seen ^M characters getting appended in the content. How to get rid of it ?...
  • SSH: Whitelist IPs for Your Server

    If you wish to whitelist certain IP’s for your server for any reason, you can easily go into your Webair Ezpanel for this. When whitelisting an IP, please provide the specific...
  • Verify RPM package integrity

    In the case of Centos/RedHat OS, RPM tool can be used to verify the integrity of the installed package and check if any of the package has been compromised or not....