1

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.

muru
  • 193,181
  • 53
  • 473
  • 722
Henry
  • 644
  • 5
  • 9
  • 16

1 Answers1

1

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 -
terdon
  • 98,183
  • 15
  • 197
  • 293
  • It works but creates a gzip archive. I need tar volumes (and ONLY tar). – Henry Aug 15 '16 at 09:18
  • @Henry OK, see update. I used the `z` flag because you did in your comment, so I assumed you wanted it compressed. – terdon Aug 15 '16 at 09: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. – Henry Aug 15 '16 at 09: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. – terdon Aug 15 '16 at 09:31
  • Ok, my mistake. I thought tar could split one file into multiple volumes (not necessarily compressed). – Henry Aug 15 '16 at 09:38