Introduction
I'm not using CentOS and therefore all my answers are not verified on this operating system.
WinRAR is installed usually on Windows with 3 executables:
- GUI version
WinRAR.exe
supporting compression in RAR and ZIP format and even more common archive formats for extraction (shareware).
- Console version
Rar.exe
supporting compression and extraction of RAR archives only (shareware).
- Console application
UnRAR.exe
for extraction of RAR archives only (free, no license needed).
In program files folder of WinRAR there is additionally the text file Rar.txt
which is the manual for the console version Rar
. GUI Version WinRAR
supports nearly same set of switches, but there are some differences like -af<type>
supported only by GUI version. The complete list of switches for WinRAR
can be found in help on page Alphabetic switches list (Contents - Command line mode - Switches). Rar
and UnRAR
output both a short help with listing all supported commands and switches if executed in a command prompt window without any parameter.
Extraction from several password protected multivolume archives
The switch -p[pwd]
can be used on command line to extract files from a password protected archive of any type as explained for example in Rar.txt
.
Examples:
UnRAR.exe x -pPasswordOfArchive MyArchive.rar
UnRAR.exe x "-p!Password Of Archive!" MyArchive.rar
This switch with the password must be enclosed in double quotes if the password contains 1 or more spaces or other special characters according to the requirements for command line strings of the script interpreter (cmd.exe
on Windows, bash or sh on Linux).
Only the first file of a multivolume archive must be specified on command line to extract all files and folders from all volumes (parts) of an archive.
Example:
UnRAR.exe x -pMyPassword MyMultiVolumeArchive.part1.rar
The other files (parts) of MyMultiVolumeArchive
must be in same directory as first file and all parts must be present and valid.
The manual Rar.txt
contains for command rv
the paragraph:
RAR reconstructs missing and damaged volumes either when using rc
command or automatically, if it cannot locate the next volume and finds the required number of .rev files when unpacking.
I tested the statement about automatically using *.rev files and it is not 100% true for v5.10 on Windows on extraction for multivolume RAR archives independent on which executable is used and if the multivolume RAR4 archive is password protected, completely encrypted or not protected. A missing part is automatically reconstructed using the recovery volumes, but not a damaged part resulting in one or more checksum errors on extraction of files. It is necessary to run a reconstruct on a multivolume RAR archive with a damaged volume before extraction can be done for all files and folders successfully.
The manual Rar.txt
contains near top in chapter about RAR command line syntax the paragraph:
Many RAR commands, such as extraction, test or list, allow to use wildcards in archive name. If no extension is specified in archive mask, RAR assumes .rar
, so *
means all archives with .rar
extension. If you need to process all archives without extension, use *.
mask. *.*
mask selects all files. Wildcards in archive name are not allowed when archiving and deleting.
So extraction of all files and folders from all password protected multivolume RAR archives in same directory is very easy:
UnRAR.exe x -idcdp -pCommonPassword *.rar
UnRAR
automatically detects all *.rar files in the directory independent on type (single or multivolume archive) and decompresses them all whereby nothing is extracted twice. So after extraction of MyMultiVolumeArchive.part1.rar
it continues automatically on part 2, 3, ... and after processing this multivolume archive, continues with next archive with a different file name in same directory.
It might be useful to use additionally the switch -ad
to extract all files and folders of an archive to a folder with name of archive file to avoid extraction of files from different archives into same directory.
Example:
UnRAR.exe x -idcdp -ad -pCommonPassword *.rar
But take into account that the created folder contains also .part*1
in name for a multivolume archive. So using this switch on multivolume archives does not produce nice looking folder names.
On Windows the following command can be used to remove .part*1
from all folder names:
for /F "usebackq delims=" %D in ( `dir *part* /AD /B /ON` ) do ren "%D" "%~nD"
As batch file:
@echo off
for /F "usebackq delims=" %%D in ( `dir *part* /AD /B /ON` ) do ren "%%D" "%%~nD"
It is not possible to specify several RAR archives on a command line without usage of wildcards.
A command line like
UnRAR x -pArchivePassword FirstArchive.part1.rar SecondArchive.part001.rar ThirdArchive.rar
would be interpreted as order to extract the files SecondArchive.part001.rar
and ThirdArchive.rar
from multivolume archive FirstArchive
.
Reconstruct several password protected multivolume archives
The command rc
must be used instead of x
to reconstruct a multivolume archive using recovery volumes (*.rev).
This command is not supported by UnRAR
, only by Rar
and WinRAR
.
It is not possible to reconstruct all multivolume RAR archives in a directory with a single command. If a wildcard like *.rar
is used with command rc
, just the first RAR archive matching the file mask will be processed for checking archive integrity and reconstruct a volume if damaged or missing.
Therefore a command line respectively shell script (*.bat, *.sh) is required to run RAR with command rc
on all multivolume archives in a directory.
But it is not necessary to first test archive integrity on each multivolume archive using command t
as archives with no damaged or missing volume are not modified at all on reconstruct.
Example for a single archive:
Rar.exe rc -pArchivePassword MyMultiVolumeArchive.part001.rar
Here is a Windows batch file for that task:
@echo off
setlocal EnableDelayedExpansion
for /F "usebackq delims=" %%F in ( `dir *part*1.rar /A-D /B /ON` ) do (
rem Get string of archive file name after first dot which should be
rem the dot before part*1 as otherwise this procedure would produce
rem a wrong result. In other words this procedure does not work with
rem archive file names containing an additional dot before .part*.rar.
for /F "tokens=1,2 delims=." %%M in ( "%%~nF" ) do (
set PartNumber=%%N
rem Remove all zeros from "part*1"
set PartNumber=!PartNumber:0=!
rem Remove also "part" from "part*1".
set PartNumber=!PartNumber:part=!
rem Check if part number is 1 and not 11 or 101 or 111.
if "!PartNumber!" == "1" (
echo.
echo Reconstruct archive %%M
"C:\Program Files\WinRAR\Rar.exe" rc -idcd -pArchivePassword "%%F"
)
)
)
endlocal
Create a RAR archive for each subdirectory in a directory
WinRAR
has after pressing button Add in toolbar the option Put each file to separate archive on tab Files explained in help opened by pressing button Help. WinRAR
creates for each selected folder and selected file in root of the current directory a separate archive with name of folder / file.
But this is a feature supported by WinRAR
only on using GUI. It is not supported on command line as far as I know whether by WinRAR
nor by Rar
.
Therefore it is necessary to run a small command line / shell script (*.bat, *.sh) to compress each folder in a directory into a separate archive. Just a single line is necessary to achieve that at least on Windows.
Windows command line:
for /F "usebackq delims=" %D in ( `dir /AD /B /ON` ) do "C:\Program Files\WinRAR\Rar.exe" a -cfg- -ep1 -inul -m5 -r -t -v10M "%D.rar" "%D"
Windows batch file:
@echo off
for /F "usebackq delims=" %%D in ( `dir /AD /B /ON` ) do "C:\Program Files\WinRAR\Rar.exe" a -cfg- -ep1 -inul -m5 -r-t -v10M "%%D.rar" "%%D"
The example compresses each folder recursively to an archive with same name using best compression, omitting the path to the folder in archive and creating a multivolume archive with 10 MB per volume. The created archives are additionally tested for integrity although this is usually not needed.
UnRAR.exe x -ptest TestArchive.part1.rar TestArchive2.part1.rar
? – user332153 Aug 11 '14 at 13:32