Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merge and extract tgz files from Google Takeout

Recently found some clowny gist was the top result for 'google takeout multiple tgz', where it was using two bash scripts to extract all the tgz files and then merge them together. Don't do that. Use brace expansion, cat the TGZs, and extract:

$ cat takeout-20201023T123551Z-{001..011}.tgz | tar xzivf -

You don't even need to use brace expansion. Globbing will order the files numerically:

$ cat takeout-20201023T123551Z-*.tgz | tar xzivf -

tar has been around forever, they didn't design it to need custom scripts to deal with multipart archives. Since it's extracting the combined archive, there's no 'mess of partial directories' to be merged. It just works, as intended.

An additional tip, courtesy of Dmitriy Otstavnov (@bvc3at): if you have pv available, you can track the progress of the extraction:

> pv takeout-* | tar xzif -
 190GiB 2:37:54 [18.9MiB/s] [==============>                                   ] 30% ETA 5:03:49
@sagz
Copy link

sagz commented Oct 20, 2022

On MacOS (Mojave or Ventura+), there's a small mod:

pv takeout-* | gtar -xzif -

(if you don't have pv, then install with Homebrew: brew install pv. Also, MacOS uses bsdtar which doesn't support -i ignore zeroes, so use gnutar; installable with brew install gnu-tar)

@Jinion7
Copy link

Jinion7 commented Nov 14, 2022

On MacOS (Mojave or Ventura+), there's a small mod:

pv takeout-* | gtar -xzif -

(if you don't have pv, then install with Homebrew: brew install pv. Also, MacOS uses bsdtar which doesn't support -i ignore zeroes, so use gnutar; installable with brew install gnu-tar)

This worked for me seamlessly. Thank you!
(MacBook Pro M1 Max Ventura 13.0.1)

@roidave
Copy link

roidave commented Mar 22, 2023

On MacOS (Mojave or Ventura+), there's a small mod:

pv takeout-* | gtar -xzif -

(if you don't have pv, then install with Homebrew: brew install pv. Also, MacOS uses bsdtar which doesn't support -i ignore zeroes, so use gnutar; installable with brew install gnu-tar)

Worked great! Thanks all!

@rcarteraz
Copy link

rcarteraz commented May 31, 2023

Arrived here from the previously mentioned page... What's the best option for macOS if I went with the zip option? I went with unzip '*.zip' -d complete-takeout but it only processed two of the files because one had "fatal errors" but it didn't provide any details. I can unzip them individually without issue but I would prefer a method that combines them so I don't have to do it manually.

@chabala
Copy link
Author

chabala commented Jun 1, 2023

What's the best option for macOS if I went with the zip option?

Re-request the Takeout with tar.gz. Otherwise, Stack Overflow: https://unix.stackexchange.com/a/40565/19124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment