简体   繁体   中英

Extract tar file using bash script

Hi I am working with Bash Script and i have difficulty on extracting a tar file and inside of the tar file is another tar file . Please see below code and please provide me with feedback because the only thing that the code do will just extract the the first tar file and remove it.

#!/bin/bash

output=$(df -h)
bundle=$(awk -F = '{print $2}' config.txt)
bundlename=$(echo $bundle | awk -F / '{print $11}')  
echo "$output"

wget $bundle
echo "$bundlename"
tar -xzvf "$bundlename"
rm -vf "$bundlename"

My question is what is the right way/code to extract all the tar file inside the tar file ?.

you can pipe the output of the tar extract to the tar command again to run it. for example:

tar -xvf xyz.tar |grep '\.tar$' | xargs -n 1 | tar -xvf

but this will only extract one level tar files, if the extracted tar contains another tar, then again you will have to pipe it. I hope you get the point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM