I have a lot of rar archives structured in individual folders and would like to script unpacking them all.
I'm having trouble figuring out how it should be done and need some help.
#!/bin/bash
## For all inodes
for i in pwd; do
## If it's a directory
if [ -d "$i" ] then
cd $i
## Find ".rar" file
for [f in *.rar]; do
./bin/unrar x "$f" # Run unrar command on filename
cd ..
done
done
done
I am not familiar with bash scripting and I assume the code is wrong more than once. But I guess this should be the basic structure
Find exec causes find command to execute the given task once per file is matched. It will place the name of the file wherever we put the {} placeholder. It is mainly used to combine with other commands to execute certain tasks.
Find exec multiple commands syntaxThe -exec flag to find causes find to execute the given command once per file matched, and it will place the name of the file wherever you put the {} placeholder. The command must end with a semicolon, which has to be escaped from the shell, either as \; or as " ; ".
You can use the find
command:
find -name '*.rar' -exec unrar x {} \;
find
offers the option exec
which will execute that command on every file that was found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With