Unrar – Delete archive(s) after extraction

Due to lack of disk space on a server I needed a mechanism for automatically deleting RAR archives after their contents had been extracted. I couldn’t find any particularly neat way to do this with a shell script so I knocked up the following quick & dirty patch for unrar.

The patch applies cleanly to version 5.1.6 of the unrar source as follows:

wget 'http://www.rarlab.com/rar/unrarsrc-5.1.6.tar.gz'
tar -xvzf unrarsrc-5.1.6.tar.gz
cd unrar
wget 'http://simon.aldrich.eu/download/unrar/unrar-deleteOnExtract.patch'
patch -p1 < unrar-deleteOnExtract.patch
make

The compiled unrar binary will have the following extra option:

de  Delete archive(s) after extracting

Which you can use with the -e or -x commands e.g.:

unrar x -de test.part01.rar

Hopefully this might be useful to someone other than just me. Although, obviously, if extraction fails for any reason you will have deleted all the earlier volumes in the archive set. My suggestion would be to use the -t command to test your archive(s) first. I take no responsibility for any screw-ups you may cause yourself if you use this patch – caveat emptor!

2 Replies to “Unrar – Delete archive(s) after extraction”

  1. Why wouldn’t
    unrar x archive.rar && rm -rf archive.rar

    Work then? Not that I know anything of unrar, but I’d hope that it succeeds if the extraction works and fails otherwise?

    Wakka-chikka…..

    1. That works for the simple case when you only have a single archive to extract. However (un)rar supports multiple-volume archives where a set of archive files contain the compressed data. That’s mostly what this patch is to cover. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *