Tar gotcha: extract from multiple tar files in one go

October 18th, 2014 | Tags: , ,

Suppose you have a monthly process to archive some data such as log files etc. Each month a separate archive file is created, and so after a few months you will have several archive files – for example as shown below:


Now if you wish to extract your data from all three files, you could run individual commands such as:

This works fine. However the following won’t work if you want a one-line which does them all in one short:

Basically the way that tar command works, if more than one filename (or an expansion) is passed as an argument, it will look for the second, third, etc. files inside the first file. So the error is saying it cannot find the second and third archive file inside the first one (archive.2014-08.tar.gz). So in essence the tar command itself really does have to be called individually for each file. The way to simplify this on a one-liner is to use the xargs command which will do exactly that:

No comments yet.