Compress and split files in the file explorer

If you right click a file in Nautilus and select Compress, then you get a dialog where you can choose a compression format and a filename. If you click on Advanced, then there are settings to split and compress the file, but it's deactivated/insensitive. How come and how do I activate those features?

Edit: In an answer below, it has been suggested that it has something to do with rar. But I have that installed, and I don't get the options to split.


Solution 1:

Only some archiving tools support splitting. One of them is RAR -- package rar (but it's shareware and you need to buy it after 40 days -- Shareware in Ubuntu repositories? (RAR)) and another is for example 7zip -- package p7zip-full. You need to install one of them (I suggest 7zip because it's completely free).

You can also create a sigle archive and then split it into parts using split command (or HJSplit for GUI).

Solution 2:

To activate the split option, select .rar from the file extension drop-down box.

enter image description here

Solution 3:

Try replacing rar by unrar-free or the other wise around.

This can be done by simply

sudo apt-get install rar unrar-free

Solution 4:

Considering the specific case of multi-segment ZIP files,

this is a complementary answer to the main one.

As already stated in the main answer, only some archiving tools support splitting, and the main GUI doesn't seem able to create multi-segment archives in zip format. Alternative formats can be used though, namely rar and 7z.

Also, only some tools can extract from multi-segment-zip-files, such as the ones discussed here: on that, see the end-note to this answer.

As the question specifically addresses the issue of handling archiving from the context menu of the file manager, I looked into some commands that could achieve the given purpose even for zip files: such commands, if successful, could then be easily added to the file manager as context menu entries.

Considering the zip tool, multi-segment archives can be created directly with a command like zip my_archive.zip -r <file> -s 20971519 (more details under this question), but these are not at all useful because they are not ready to be extracted (need a supplementary zip -s 0 command to create a large 1-file extractable archive - as described here) and this limitation cannot be avoided. Sending a such multi-segment archive to somebody that doesn't know this is pointless.

As already suggested in the main answer, another way is to zip the file and then split the one-file archive with split (or the hjsplit GUI). (I have tested the GUI and I found it extremely slow, while for the context-menu purpose the GUI is not needed.)

The idea is to add to the context menu of the file manager an entry that, with just one click, would

  1. compress selected files as a single zip file,
  2. split the zip-file in parts of specified maximum size, and
  3. remove it in order to keep only the multi-file archive.

So, I have tested with Thunar and a custom action with these three commands connected by &&:

zip -j my_archive.zip %F && split -b 20m my_archive.zip split.zip && rm my_archive.zip

(That is to be applied to one or more selected files, but not to directories; to apply to directories, the zip -r option is needed:

 zip -r -j my_archive.zip %F && split -b 20m my_archive.zip split.zip && rm my_archive.zip

)

  • -j stands for an option for zip to "junk the path": unlike a terminal command containing the full path of the to-be-archived file(s) , a context menu command that uses %F for selected files would add to the archive a folder-in-folder structure unless -j is used; (source: create zip - ignore directory structure);

  • my_archive.zip is the custom name of the not-yet-split archive; the split command will be applied to it and then the former will be removed with rm

  • %F can be used in a Thunar custom action in order to compress multiple files as zip; alternatively, %f is to be used for selection of just one file;

  • -b 20m stands for the size of the separate archive parts created by split as indicated here;

  • split.zip is a specification that is not needed; it is the custom name of the final multi-file archive, it would give something like split.zipaa, split.zipab, split.zipac..., and without it the output will be named x followed by the aa fragment-suffixes: xaa, xab, xac..., etc; there is a split option -d to use numeric suffixes instead of alphabetic, but that gives an error (because apparently the extractor expects a standard ZIP multi-segment archive when it sees a numeric suffix - as suggested in a private chat by Stephen Kitt;

  • rm applied to the my_archive.zip file will only leave us with the desired multi-segment archive.


Note:

In order for the resulting multi-zip-archive to be extracted, a tool that supports aa segmentetd archives is needed, like file-roller in Linux and 7-Zip in Windows.