-3

I'm new to working in the shell and can use the unrar command to extract a single archive but I'm looking to do a lot more then that. Let me explain.

Ex:

/ParentFolder/ChildFolder1/xyz.rar

/ParentFolder/ChildFolder2/abc.rar

/ParentFolder/ChildFolder3/rty.rar

/ParentFolder/ChildFolder4/wqe.rar

Each child folder has different names, each containing differently named archives. I would like to build a script that will extract the archives inside every child folder, and also renaming the extracted file to the same name as the folder.

BONUS: Each child folder has archives that are listed like

archivename.r01

archivename.r02

archivename.rar

If its possible to delete the entire archive structure after extraction that would be AMAZING.

Hopefully I explained this well enough. Thanks in advance!

  • 5
    You should likely try something first and explain what you are having issues with, otherwise this question sounds like a request for someone to do free script development. – l'L'l Jul 23 '17 at 19:06
  • Your "input" example is very good (i.e. `/ParentFolder/ChildFolder1/xyz.rar .....`). Edit your Q to show what you would like as your final output and then we won't be guessing what you mean. Good luck. – shellter Jul 23 '17 at 20:22

1 Answers1

0
find /ParentFolder -name "*.rar" -exec unrar '{}' \;

Find all archive files in the directory structure and unrar.

find /ParentFolder ! -name "*.rar" | awk -F \/ '{ split($4,fle,".");system("mv "$0" "$2"/"$3"/"$3"."fle[2]) }'

Assuming there are no other files already in the directory structure, the unarchived files will not be files with the rar extension and so look for all those file without rar as an extension and pipe the results through awk, using the system function to rename the file with mv.

find /ParentFolder -name "*.rar" -exec rm -f '{}' \;

Finally run the find command for all rar files and run the rm -f command to remove them.

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18