Pages

Saturday, November 21, 2015

[Linux] Unzip tarballs to corresponding directories

Assume you have a tarball mySource.tar, which contains multiple tarballs inside, each inner tar balls contains multiple files. Now we want to unzip the tar balls and create one directory for each tar ball.

This task can be split into two steps:
1. Unzip a tarball, and put it into a directory
mkdir -p myOut && tar -C myOut -xv mySource.tar
2. Unzip multiple tarball, and put it into its corresponding directory. For example, the files in group1.tar will be extracted to a directory group1.

# in the directory, say, myOut
for  i in *.tar; do mkdir -p {i%.*};&& tar -C {i%.*} -xv $i; done
Please note that it works for a flat (not recursive).

No comments:

Post a Comment