0
shopt -s globstar
for f in **/*.rar; do
    dir=`dirname "$f"`;
    unrar e "$f" "$dir" && rm -frv "${f::-2}*";
done

From echoing out testing the rm command, the file is the correct path. I don't receive any errors about an incorrect path or anything. I know there are other methods to use find, but that would be pointless and use extra cpu cycles this should be working from everything I found. Any ideas on how to use the rm command properly?

1

It should work with removing the double quotes:

shopt -s globstar
for f in **/*.rar; do
    dir=`dirname "$f"`;
    unrar e "$f" "$dir" && rm -frv ${f::-2}*;
done

Bash expansion of the star char * doesn't occurs inside quotes.

For example:

echo dir/*.rar might give:

dir/file1.rar
dir/file2.rar
dir/file3.rar

But echo "dir/*.rar" will give:

dir/*.rar

(rm command will try to delete a filename which contains literally a star character.)

  • Hey thank you so much! I should have interpreted the output of the error by it not finding the filename/r* as a literal search for that. I was just confused on the echo displaying it correct. – user316523 Jan 8 at 10:32

You must log in to answer this question.