Compress directory in Linux for various reasons is very essential for Linux’s users daily work, in one of the previous posts we already discussed it in detail, how can we compress various file and directories in gzip and bzip2 format and finally create one tar file contains all in one package. we can further use this bundle to mail, transport, copy, share with other user, systems for usage, this makes it very useful but what if we like to uncompress it on another place, like other than current one. In this post, we will check how can we extract any tar (gzip and bz2) on another directory than the current one.

This kind of requirement happened many times, where we don’t need to work uncompress data on the same place or we don’t have enough space on same mount point and also could some other reasons as per user setup. So with all these requirements its important to know a way to extract tar files on another destination instead of the current one.

For same we have -C option in tar command which changes to Directory (provide one). This is quite an easy way to save extract data in the mentioned directory instead of current.

Extract tar file

For extract any tar files we need to use below command.

tar -xvf file.tar -C <destination-directory-path>

This above syntax will uncompress tar file content into destination-directory

Extract tar Gzip file

For extract any tar files we need to use below command.

tar -xzvf file.tar.gz -C <destination-directory-path>

This above syntax will uncompress tar Gzip file content into destination-directory

Extract tar Bzip2 file

For extract any tar Bzip2 files we need to use below command.

tar -xvjf file.tar.bz2 -C <destination-directory-path>

This above syntax will uncompress tar Bzip2 file content into destination-directory