How to unrar and unzip files recursively?

I have a massive documents which contains zips and also rars with zip and also rar documents situated within on a linux box.

I primarily require a manuscript or one - lining that will recursively quest via the directory sites and also unzip and also unrar any kind of rar or zip it locates.

2
2022-07-25 17:25:56
Source Share
Answers: 4

Here is someones remedy to this with a shell script.

Presumably that Linux does not have a recursive unzip alternative: (

2
2022-07-25 19:46:48
Source

The only means I can consider doing this is to loop numerous times with locate and also execute a manuscript that gets rid of the documents after they've been appropriately unpacked. It'll need to go over subdirectories numerous times so it is not specifically reliable. (anticipated filenames in vibrant ahead)

recursive_unpack

#!/bin/bash
if [ -d "$1" ]; then
   STARTDIR="$1"
else
   echo "starting dir not found: $1"
   exit
fi


COUNTER=1
while [ $COUNTER -gt 0 ]; do
   COUNTER=`find "$STARTDIR" -type f \( -iname '*.zip' -o -iname '*.rar' \) -exec ./unpacker \{\} \; | wc -l`
done

unpacker

#!/bin/bash
BASENAME=`basename "$1"`
BASEDIR=`dirname "$1"`

cd "$BASEDIR"
EXT=`echo "$BASENAME" | awk -F . '{print $NF}'`

if [ "$EXT" = "zip" ]; then
  unzip -qq "$BASENAME"
  if [ $? -eq 0 ]; then
     echo "zip unpacked: $1"
     rm "$BASENAME"
  fi
fi

if [ "$EXT" = "rar" ]; then
  unrar e -y -c- -inul "$BASENAME"
  if [ $? -eq 0 ]; then
     echo "rar unpacked: $1"
     rm "$BASENAME"
  fi
fi

do

chmod u+x recursive_unpack
chmod u+x unpacker

call it with ./recursive_unpack "/my/directory/containing/my/files"

  • recursive_unpack anticipates unpacker in the very same directory site
  • unrar and also unzip require to be mounted
  • if it can not locate the directory site it'll exit with a mistake
  • do not remove the resemble messages in unpacker, they are made use of to look for the visibility of documents to unbox to end the loop
1
2022-07-25 19:46:48
Source

A fast one - lining, does not examine if an archive has actually currently been extracted:

$ find . -name '*.rar' -execdir unrar e '{}' + && find . -name '*.zip' -execdir unzip -tq '{}' +
1
2022-07-25 19:46:48
Source

Maybe dtrx () will do, though I'm not sure whether it handles rar type.

0
2022-07-25 19:35:33
Source