What is the command to simply archive a file in multiple volumes with tar.
I have a file called file0
, I want to archive it with tar so that file0
is split in tar files of let us say 10MB. How can I simply do that ? The GUI of Ubuntu has the option "Split" (for tar) greyed out.
1 Answer
A simple way is to just tar the file, print the archive to standard output and pass it through split:
tar czpf - file0 | split -d -b 10M - file0
Note that this isn't quite what you tried. The command you have in your comment (tar czpf - . | split -d -b 10M - file0
) was using .
as input. That means that the input "file" for tar
, the current directory, changed as soon as split
started writing its output files into the current directory, so tar
complained. To avoid that, either give tar
the file name as I did above, or run this from another directory:
cd /some/place
tar czpf - /path/to/dir/containing/file0 | split -d -b 10M - file0
In both cases, to untar the file, you'll have to cat the files to join them:
cat file00* | tar xzvf -
-
It works but creates a gzip archive. I need tar volumes (and ONLY tar).– HenryAug 15, 2016 at 9:18
-
@Henry OK, see update. I used the
z
flag because you did in your comment, so I assumed you wanted it compressed.– terdonAug 15, 2016 at 9:19 -
It creates the volumes, the first volume is displayed with the icon of a tar file, but the other volumes have no icon (binary). When I try to extract the files (right click on the first volume) it says: file format not recognized.– HenryAug 15, 2016 at 9:26
-
@Henry please edit your question and explain what you need in more detail. For one thing, there's no point in creating a tar of a single file unless you're compressing it. Which means that my answer is kind of pointless without the
z
(as I just realized, so I put it back). I think you're looking for something like the multi-file archives offered by rar. That's not something tar can do. More importantly though, please explain what you're trying to achieve by tarring a single file.– terdonAug 15, 2016 at 9:31 -
Ok, my mistake. I thought tar could split one file into multiple volumes (not necessarily compressed).– HenryAug 15, 2016 at 9:38
tar
? If it's just one file, use just ONE command:split
.