Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So how should this be done? I have learned that using cat is the preferred way when using split to create multi-volume files, but what about when using tar's own native multi-volume function?


share|improve this question
up vote 2 down vote accepted

In this answer I give an answer using a callback script, to be used with the -F option of tar.

Here I expand on the automated input to tar prompt requests, both in the creation and the extraction of the archive, and estimating in advance the number of volumes needed:



# estimated number of volumes: dir-size / vol-size + 1
# adding a further +1 to be safe
n=$(($(du -s Documents2 | awk '{ print $1 }') / $vol_size + 2))

for ((i = 2; i <= n; i++)); do printf 'n file-%d.tar\n' $i; done |
  tar -ML $vol_size -cf file-1.tar Documents2/ 2>&-



n=$(printf '%s\n' file-*.tar | sed 's/^file-//;s/\.tar$//' | sort -nr | head -1)
for ((i = 2; i <= n; i++)); do printf 'n file-%d.tar\n' $i; done |
  tar -M -xf file-1.tar 2>&-
share|improve this answer
Hi again :) The extraction script just seems to freak out, so I removed the "to null bit in the end" and found out that it says (freely translated from Swedish to English) Prepare volume 2 for file-20.tar and press carriage return: tar file end on expected user answer. Tar: Error can not be handled, exiting. Any ideas? :) – Industrial Sep 25 '11 at 20:11
@Industrial: you are right, there was an error: the two for loops should begin from 2, not 1. Corrected the answer. – enzotib Sep 26 '11 at 7:12
Hi again! You are really amazing helping me out with this. I have absolutely no idea on what to do now. I managed to get the script running properly at my Ubuntu 10.04 workstation, but when I deploy it to the Debian server where it is meant to live, I get this error: Prepare volume #2 for "file-4.tar" and hit return: tar: EOF where user reply was expected tar: WARNING: Archive is incomplete tar: Error is not recoverable: exiting now. – Industrial Sep 26 '11 at 10:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.