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!