문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top