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

  • Using Top [ $top ]

    What is Top? Top provides a live display of information on the CPU processes. Top gets updated periodically as it provides an output CPU level percentage, Memory size, Swap Info,...
  • Assign range of IP addresses to an interface.

    Sometimes you may need to assign a wide range of IP addresses to your network interface in Linux systems. Instead of manually creating aliases for the network interface, it is...
  • Scanning for rootkits and possible exploits – RKHunter

    Rootkits are malicious softwares that are installed by intruders to gain access to your server once the security of the server has been breached.  Intruders can leave some malicious softwares...
  • Disable SELinux

    Security-Enhanced Linux (SELinux) is a mandatory access control (MAC) security mechanism implemented in the Linux kernel. This mechanism adds an extra layer of access security to your files,directories,devices, ports and...