Extracting tar is a common thing to do and everybody familiar with unix and linux knows how to do it. Usually the files will be extracted to the current directory. There is although one small trick to do to send the files to the desired location. Use the below command:
# tar -xvzf filename.tar.gz -C /desired/path
This command will extract(-x) verbosely(-v) tar gz(-z) file(-f) to the desired location. Hope this will help. Cheers
Thursday, February 28, 2008
Extracting tar into chosen directory
Subscribe to:
Post Comments (Atom)
15 comments:
Very well written! Your topic was easy to find and well said, meaning I understood it. Too many tutorials are poorly explained and you even explained the command variables xzvf.
Thanks for this!
Thanks!
here major flag is '-C' which has following man page entry:
-C directory
In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive.
yeah thanks help a lot
Great.. Simple is perfect.
Very useful command , thanks a lot
this command helped me a lot at right time
HEY...SIMPLY GREAT...
IT WORKS!!!!
Perfect, thanks for the guidance. I was able to put together this script using xargs to extract tgz files to directories names after the files.
ls *.tgz |cut -f1 -d'.' |xargs -L1 mkdir
ls *.tgz |cut -f1 -d'.' |xargs -L1 -I{} tar xzfv {}.tgz -C ./{}/
Thanks for the explanation.
Thanks to Chandan for explaining the '-C' , too.
Thank you
Tnx!
@ArmHead, the following command does the same (and removes archives if tar succeeds) in an easier way. You can even type it on a single line.
for i in *.tgz; do
mkdir -p ${i%.tgz};
tar xzfv $i -C ${i%.tgz} && rm $i;
done
However, you might need to modify it if your *.tgz files contain a whitespace, a tab or a newline character in their names.
Thanks!!!
How to extract specific folder from tar.gz file
I have tried below command:
# tar -xvzf test.tar.gz MyPersonal
MyPersonal is a folder name.
Post a Comment