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
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.
ReplyDeleteThanks for this!
Thanks!
ReplyDeletehere major flag is '-C' which has following man page entry:
ReplyDelete-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
ReplyDeleteGreat.. Simple is perfect.
ReplyDeleteVery useful command , thanks a lot
ReplyDeletethis command helped me a lot at right time
ReplyDeleteHEY...SIMPLY GREAT...
ReplyDeleteIT 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.
ReplyDeletels *.tgz |cut -f1 -d'.' |xargs -L1 mkdir
ls *.tgz |cut -f1 -d'.' |xargs -L1 -I{} tar xzfv {}.tgz -C ./{}/
Thanks for the explanation.
ReplyDeleteThanks to Chandan for explaining the '-C' , too.
Thank you
ReplyDeleteTnx!
ReplyDelete@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.
ReplyDeletefor 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!!!
ReplyDeleteHow to extract specific folder from tar.gz file
ReplyDeleteI have tried below command:
# tar -xvzf test.tar.gz MyPersonal
MyPersonal is a folder name.