August 29, 2015

Code Snippet: Bash Script to Unrar Files to Same-named Subdirectories

#! /bin/sh

# unrar all rar files in current dir to same-named subdirectories 
# ref:
# ref :

echo "starting unrar in folders"

# for everything named *.rar
for filename in *.rar


foldername=$(basename "$filename" .rar)
echo $foldername
mkdir "$foldername"
cd "$foldername"
unrar x ../"$filename"
cd ..


echo "finished unrar in folders"
categories: code-snippets