How to Extract rar file and skip existing files using a Command in Command Line Interface

Posted on


This is a tip for using the command available in Linux or Unix operating system family. This command is common in the Linux or Unix operating system. The main function of this command is to extract files from a rar file format. In this context, a rar file format is a compressed file. It is normally a file that ends with the extension of ‘.rar’. In order to extract the file, it need a tool represented by a command. That is a tool where the execution of it is very simple. Just type the tool name where it will act as a command in the command line interface. That tool name is ‘rar’.

According to the manual page the ‘rar’ tool, it is a command to archive files with compression. Fortunately, that is not the limit of the ‘rar’ tool usage. It also can extract the compression files that ends with the extension or ‘.rar’. But what is the main reason for skipping the existing files for the extraction process ?. It is possible if there is an attempt for extracting the compressed file but it failed in the middle of the extraction process. So, instead of extracting all the files, just extract the necessary file only. Off course, it is only the file which is not extracted. The following is an output of a failed extraction process because the compressed file is corrupted :

user@hostname:~$ rar x myfile.rar

RAR 5.50 Copyright (c) 1993-2017 Alexander Roshal 11 Aug 2017
Trial version Type 'rar -?' for help

Extracting myfile.rar

Extracting db-20130315-2045.sql OK
Extracting db-20130316-2045.sql OK
Extracting db-20130317-2045.sql OK
Extracting db-20130318-2045.sql OK
Extracting db-20130308-2045.sql OK
Extracting db-20130309-2045.sql OK
Extracting db-20130310-2045.sql OK
Extracting db-20130311-2045.sql OK
Extracting db-20130312-2045.sql OK
Extracting db-20130313-2045.sql OK
Extracting db-20130314-2045.sql 99%
db-20130314-2045.sql - checksum error
Unexpected end of archive
Total errors: 2

The above extraction process failed. The compressed file actually consists of several dump database files collected in one month. Later on, those files are collected and compressed in one single compressed file. In the process of extracting back the file, apparently there is several failed extraction. It is because the compressed file itself is corrupted. In order to extract all the files, just extract the actual compressed file which is not corrupted.


Extracting File and Skipping the existing files

Since the previous process for extracting the files failed in the last part, there is no need to extract all the files from the beginning. Just extract the failed part. Below is the example of how to extract it by execute the following stepsĀ  :

1. Run the command line interface in the machine or in the operating system.

2. In order to make sure that the extraction process is really skipping the existing files, type the following command pattern :

rar l rar_file_name

The following is the execution of the above command pattern to check the content of the available files in the compressed file in the form of list :

user@hostname:~$ rar l myfile.rar

RAR 5.50 Copyright (c) 1993-2017 Alexander Roshal 11 Aug 2017
Trial version Type 'rar -?' for help

Archive: myfile.rar
Details: RAR 4

Attributes Size Date Time Name
----------- --------- ---------- ----- ----
..A.... 3252052085 2013-03-15 20:51 db-20130315-2045.sql
..A.... 3252051929 2013-03-16 20:52 db-20130316-2045.sql
..A.... 3252051929 2013-03-17 20:52 db-20130317-2045.sql
..A.... 3252051929 2013-03-18 20:52 db-20130318-2045.sql
..A.... 3254415123 2013-03-19 20:51 db-20130319-2045.sql
..A.... 3254415123 2013-03-20 20:51 db-20130320-2045.sql
..A.... 3254415123 2013-03-21 20:51 db-20130321-2045.sql
..A.... 3254415123 2013-03-22 20:52 db-20130322-2045.sql
..A.... 3254415123 2013-03-23 20:51 db-20130323-2045.sql
..A.... 3254415123 2013-03-24 20:50 db-20130324-2045.sql
..A.... 3254415123 2013-03-25 20:51 db-20130325-2045.sql
..A.... 3254415123 2013-03-26 20:51 db-20130326-2045.sql
..A.... 3254415123 2013-03-27 20:51 db-20130327-2045.sql
..A.... 3255152651 2013-03-28 20:51 db-20130328-2045.sql
..A.... 3255152651 2013-03-29 20:51 db-20130329-2045.sql
..A.... 3255152651 2013-03-30 20:52 db-20130330-2045.sql
..A.... 3255152651 2013-03-31 20:52 db-20130331-2045.sql
..A.... 3084488564 2013-03-01 20:51 db-20130301-2045.sql
..A.... 3084488450 2013-03-02 20:51 db-20130302-2045.sql
..A.... 3084488624 2013-03-03 20:51 db-20130303-2045.sql
..A.... 3107781894 2013-03-04 20:51 db-20130304-2045.sql
..A.... 3107781892 2013-03-05 20:52 db-20130305-2045.sql
..A.... 3107782375 2013-03-06 20:51 db-20130306-2045.sql
..A.... 3107782034 2013-03-07 20:50 db-20130307-2045.sql
..A.... 3222770481 2013-03-08 20:50 db-20130308-2045.sql
..A.... 3222770511 2013-03-09 20:51 db-20130309-2045.sql
..A.... 3222770470 2013-03-10 20:50 db-20130310-2045.sql
..A.... 3249458817 2013-03-11 20:51 db-20130311-2045.sql
..A.... 3249458333 2013-03-12 20:51 db-20130312-2045.sql
..A.... 3249457743 2013-03-13 20:52 db-20130313-2045.sql
..A.... 3251120947 2013-03-14 20:52 db-20130314-2045.sql
----------- --------- ---------- ----- ----
99670955718 31


But actually there is only a need to extract the failed one. So, in order to skip the existing files generated from the previous extraction process, just execute the following command pattern :

rar x -o- compressed_file_name

rar : the command to execute the rar file tool
x   : the command part available specifically to make rar tool to extract file in full path
-o- : the switch part available to inform the rar tool to skip any existing files available
compressed_file_name : the name of the compressed file

Execute the above command pattern as follows :

user@hostname:~$ rar x -o- myfile.rar 

RAR 5.50   Copyright (c) 1993-2017 Alexander Roshal   11 Aug 2017
Trial version             Type 'rar -?' for help

Extracting from myfile.rar

Extracting  db-20130314-2045.sql                                     OK 
All OK


Leave a Reply