How to Simultaneously Unrar Multiple Files at Once into Individual Folders
Suppose you have a dozen or so *.rar
files that you would like to unzip at the same time. But for each file, you want to create a folder with the same name and extract the files into that specific folder. Here are the short-hand and long-hand versions.
Getting Started
Firstly, I use Homebrew as my package manager to to install [unrar](https://formulae.brew.sh/formula/unrar)
. After installing Homebrew, you will then type.
brew install unrar && brew doctor
Multi-line
Change directory into the folder that has all of the ```.rar```files.
cd /path/to/folder/with/multiple/rar/files
Paste this script line-by-line.
# Start a loop that will iterate through each RAR file
for z in *.rar
# Start block
do
# Get the name of the RAR file by stripping out the .rar extension
name_of_dir="${z%%'.rar'}"
# Create a new directory with the name of the directory
mkdir ./"$name_of_dir"
# Extract the content into the newly created directory
unrar e "$z" "$name_of_dir"
done
Single Line
Below is the one-line code.
for z in *.rar ; do dir="${z%%'.rar'}"; mkdir ./"$dir"; unrar e "$z" "$dir"; done