How to remove all the parts of a split RAR archive file using command line?
Solution 1:
Depending on the number of .r0*
files you have you could replace the *
with a ?
this will remove files that have .r0 and 1 other character. So it will remove rabbid.ranger.robot.r01
but not rabbid.ranger.robot.r010
Generally I would use it as such:
rm filename.r??
Solution 2:
Suppose you have a split RAR with parts numbered up to 12 (i.e., filename.r12
as your last file) and you want to be extra careful not to remove any other files. Assuming bash is your shell and you're using version 4 or higher (bash --version
to check), you can create an explicit list of files easily with brace expansion:
rm filename.rar filename.r{01..12}
This will remove only those files: even files named filename.rtf
(or filename.r13
) will be spared. Depending on what other files you have (or might have) in the folder, this may or may not be preferable to the usually quite good .r??
way suggested by Devan.
Brace expansion, including numeric ranges, is a very old feature of several shells. But before version 4, bash did not support zero-padding (i.e., you want names like filename.r05
, not filename.r5
).
You can check first to see what filenames a brace expression will expand to:
$ echo filename.rar filename.r{01..12}
filename.rar filename.r01 filename.r02 filename.r03 filename.r04 filename.r05 filename.r06 filename.r07 filename.r08 filename.r09 filename.r10 filename.r11 filename.r12
(You can check expressions with *
or ?
this way, too--just remember that what it expands to depends on what folder you're in when you run the command.)