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.

5
  • 3
  • I cannot do this simple stuff in just ONE command ?
    – Henry
    Aug 15, 2016 at 8:54
  • Why do you need tar? If it's just one file, use just ONE command: split.
    – muru
    Aug 15, 2016 at 8:56
  • tar czpf - . | split -d -b 10M - file0 returns "file changed as we read it" and only the first volume is created.
    – Henry
    Aug 15, 2016 at 9:11
  • O.o You're archiving the current directory and saving the archive in the same directory?
    – muru
    Aug 15, 2016 at 9:25

1 Answer 1

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 -
5
  • It works but creates a gzip archive. I need tar volumes (and ONLY tar).
    – Henry
    Aug 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.
    – terdon
    Aug 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.
    – Henry
    Aug 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.
    – terdon
    Aug 15, 2016 at 9:31
  • Ok, my mistake. I thought tar could split one file into multiple volumes (not necessarily compressed).
    – Henry
    Aug 15, 2016 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .