Domanda

I have created a script below and when I execute it, I face a problem. Instead to extract it 5 times it will just extract once. So how to get this issue resolved?

i=0

   for tarfile in *.tar.gz;
                        do
                        ((i++))
                         [ $i = 5 ] && break ;
                tar -xzvf $tarfile
                done
                rm -rvf $tarfile

Help is greatly appreciated. I want to extract the tar.gz file and inside of it is only tar.gz file. Noted: it is decompressed 5 times and I want to get the last tar.gz file decompressed. Please help me.

È stato utile?

Soluzione

If and only if the filenames for each of the nested tar do not collide, you can do the following.

for i in `seq 1 4`; do name=$(ls *.tar.gz); tar xvfz $name; rm $name; done;

If they are all the same, like foo.tar.gz inside foo.tar.gz inside foo.tar.gz, you can simply delete the rm $name from the above.

If there are only some collisions you will have to play more clever tricks, such as moving intermediate files into another directory.

Update: If you just want to move the final tar to a new directory, just do use mv after the loop above.

mv *.tar.gz OtherDirectoryName
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top