T
T
Timuridze2020-12-01 13:22:51
linux
Timuridze, 2020-12-01 13:22:51

How to unpack several thousand *.rar archives using Bash, each archive into a separate folder?

There are many archives in a folder, each archive has several files, some of the files in the archives have the same names. Accordingly, you need to unpack these thousands of archives, each archive into a separate folder as quickly as possible.
So far I have found how to unpack the archive en masse, but then the same files are overwritten and only the last
find remains. -name '*.rar' -print0 | xargs -n 1 -0 unrar x

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xibir, 2020-12-01
@Timuridze

writing an unpack script

#!/bin/bash
find "$1" -name \*.rar -print0 | while read -d $'\0' f; do
   d=`basename "$f"`
   d="$2/${d/%.rar/}"
   mkdir -p "$d"
   cd "$d" && unrar x "$f"
done

launch
unpack "/путь/к rar файлам" "/путь/куда распаковать"

V
Voland69, 2020-12-01
@Voland69

I immediately see two options:

  • add mkdir and mv to the pipeline;
  • man unrar to specify the directory where to unpack.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question