I want to unpack a .tar.gz file to a specific directory.

The archive file is in /root/Documents. I want to unzip it into /root/Desktop/folder. The folder structure in zipped file should be preserved in the destination directory.

1 Answer 1


You have two choices:

cd /root/Desktop/folder
tar xf /root/Documents/file.tar.gz


tar xf file.tar.gz -C /root/Desktop/folder
  • thanks, how about gzip -dc archive.tar.gz | tar -xf - -C /destination ?
    – alwbtc
    Oct 19, 2011 at 13:12
  • what -C stands for? Jan 28, 2015 at 15:56
  • 4
    @AlikElzin-kilaka From man tar -C, --directory DIR change to directory DIR
    – tachomi
    Jan 28, 2015 at 16:31
  • 2
    tar -xvjf foo.tar.bz2 for those who are looking for bz2 like me
    – vladkras
    Jan 26, 2016 at 7:09
  • You actually don't have to specify the compression format anymore with modern tar. I edited the answer so it will work with bz2, xz, and whatever else you want to throw at it.
    – Patches
    Oct 8, 2016 at 23:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .