I am trying to create a multipart RAR archive on Ubuntu. The folder structure resembles:

  • folder_root
    • subfolder
    • file01.bin
    • file02.bin
    • ...
    • file100.bin

The command I am using is rar a -v5G archive.rar folder_root/ to split each archive into 5 gigabyte parts. However once rar is finished, the files inside archive.part1.rar and in the other parts are out of order, such as:

  • file02.bin
  • file50.bin
  • ...

Is there a way to add files to the archive in alphabetical order? I am using RAR 5.50. Thanks!

  • Open WinRAR and use the "Add" button. On the files tab you can specify the files to be added. When selecting multiple files in the selector dialog via holding shift keep in mind to start the selection with the last file, then press and hold shift and then select the first file. Otherwise the order will be different. – Robert Oct 16 '19 at 17:31
  • Out of curiosity, why do you need them to be in order in the rar volumes? – Eduardo Trápani Oct 16 '19 at 17:33
  • @Robert Unfortunately I am on a headless machine. – Titan Oct 16 '19 at 18:10
  • @Eduardo Trápani When unarchiving another process needs to use them, and this one needs to be done in order of how the files are listed. I'd like to process them asap to save time. – Titan Oct 16 '19 at 18:11

This first solution is not really scalable, because it depends on the number of files, but you could provide the list of files already sorted to rar and it will honor the order.

On the compressing side you could do something like this, you will have to tweak it if you names with spaces for example:

rar a -v5G archive.rar $(find . -type f folder_root/ | sort)


rar a -v5G archive.rar folder_root/subdir folder_root/file*bin

You can specify/'find' the ones you want to have ordered and leave the rest to recursion. This last line might help trim down the number of files you need to explicitly pass to rar.

  • Thanks for the response. I was hoping for a native solution but this works as well. I was having some trouble with the file names with spaces but I eventually came up with this: eval rar a archive.rar "$(find folder_root/ -name "*.*" | sort | sed -e 's/^/"/g' -e 's/$/"/g' | tr "\n" " ")" What this basically does is pipe all the filenames with a ., sorts them, encapsulates them with quotations, and places them all on a single line for rar to process. – Titan Oct 16 '19 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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