How do I unzip a tar gz archive to a specific destination?
242,687
You have two choices:
cd /root/Desktop/folder
tar xf /root/Documents/file.tar.gz
or
tar xf file.tar.gz -C /root/Desktop/folder
Related videos on Youtube
Author by
Omar Malas
Updated on September 18, 2022Comments
-
Omar Malas over 1 year
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. -
Omar Malas over 12 yearsthanks, how about
gzip -dc archive.tar.gz | tar -xf - -C /destination
? -
AlikElzin-kilaka over 9 yearswhat
-C
stands for? -
tachomi over 9 years@AlikElzin-kilaka From
man tar
-C, --directory DIR change to directory DIR -
vladkras over 8 years
tar -xvjf foo.tar.bz2
for those who are looking for bz2 like me -
Patches over 7 yearsYou 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.
-
Zoe stands with Ukraine over 2 yearsBoth of these seem to require manually creating a directory first though :/ (Not that it's hard, it's just an annoying extra command I don't wanna have to do). oh well
-
Patches over 2 years@Zoe
tar -xf foobar-1.2.tgz -C /opt --one-top-level=foobar
unix.stackexchange.com/a/478341/5164