unrar | Cheatsheet¶
Extract files matching the pattern looo from the RAR archive archive.rar to the specified path¶
Delete all files except RAR files inside the current directory¶
Uninstall UnRAR
¶
Extract a RAR archive¶
Extract 25
RAR archive files at once¶
List all JPG files inside archive.rar without extracting¶
- List by extension
Extract a specific file from archive.rar¶
Find folders starting with a character¶
Read files on the fly¶
Extract the archive inside the current directory¶
Extract the archive and its folder layout¶
Extract all files and convert files and folders to lowercase¶
Extract all files and convert files and folders to uppercase¶
Specify the character set as UTF-8¶
Add files or paths to an existing RAR file¶
Test archive files¶
Extract to a destination path¶
Freshen (update) any files in the destination directory that are older or missing¶
Read additional filter masks from stdin and list all Passwords.txt from archive.rar¶
Read additional filter masks from wordlist.txt and list them¶
Read additional filter masks from stdin and extract all Passwords.txt from archive.rar¶
Read additional filter masks from stdin and extract all files matching the filter masks¶
Read output on the fly¶
Retrieve comprehensive information about the files within a RAR archive¶
Diff two RAR files¶
Diff two archives and dump matched files only¶
List directories up to a maximum depth of 2 using awk¶
Verbosely list archive contents
Rename all duplicate files to avoid overwriting
#!/bin/bash
# Author: wuseman
#
# Description:
#
# This script helps ensure that duplicate files extracted from the RAR archive are not overwritten.
# It uses a loop to extract the log.txt file, perform modifications, and rename the file with a
# counter to create unique filenames for each extraction. The loop continues until there are no
# more files matching the criteria. This prevents any extracted files from being overwritten and
# allows you to retain all versions of the extracted files.
#
counter=1
while unrar e -or archive.rar '*/log.txt' $dir/ |
grep -i log.txt |
sed '
s/OK/[OK]/;
s:.*/::;
s/log.txt/logs.txt/g'
do
mv logs.txt "logs($counter).txt"
((counter++))
done
Parallel extraction of RAR files
In this script, we define a function extract_rar
that takes two arguments: the RAR file to extract and the destination directory. The unrar
command is used to extract the RAR file in the background by appending &
to the command.
We then call the extract_rar
function for each RAR file you want to extract, providing the appropriate file and destination arguments. Replace "file1.rar"
, "/path/to/destination1"
, "file2.rar"
, and "/path/to/destination2"
with your actual RAR file names and destination directories.
The wait
command is used to ensure that the script waits for all the background processes to finish before exiting.
This script allows the two RAR files to be extracted in parallel, maximizing efficiency by utilizing multiple processes.
#!/bin/bash
# Author: wuseman
#
# Description: This script demonstrates how to extract two RAR files in parallel.
# Function to extract RAR file in the background
extract_rar() {
unrar x "$1" "$2" & # Extract the RAR file in the background
}
# Call the function for each RAR file
extract_rar "file1.rar" "/path/to/destination1" # Replace "file1.rar" and "/path/to/destination1" with your desired values
extract_rar "file2.rar" "/path/to/destination2" # Replace "file2.rar" and "/path/to/destination2" with your desired values
# Wait for all background processes to finish
wait # Wait for all the extraction processes to complete