Write a Shell Script to Find All Zip, Rar Files Then Unzip / Unrar

#Shell Script to Find All Zip, Rar Files Then Unzip / Unrar

#!/bin/bash #this line must be in every bash script, just ensure that you use correct path

list=`find /home/yevhen/ -type f -name “*.rar”` # get list of file and write this list to variable with name list, find command used to find all files (-type f) where name match *.rar (-name key)

for line in $list; do # this line take every line from list to line variable

DEST=${line%/*} # remove from line filename, so just destination will be in DEST variable.

unrar x $line $DEST # unrar file from line variable to DEST dir

done # finish of for loop.

Output:-


    UNRAR 3.93 freeware Copyright (c) 1993-2010 Alexander Roshal

    Extracting from /home/yevhen/Dropbox/Yevhen/test.rar

    Extracting /home/yevhen/Dropbox/Yevhen/wget.sh OK
    All OK

    UNRAR 3.93 freeware Copyright (c) 1993-2010 Alexander Roshal

    Extracting from /home/yevhen/Pictures/test.rar

    Extracting /home/yevhen/Pictures/wget.sh OK
    All OK 

No comments:

Post a Comment

Thank You for your Comments, We will read and response you soon...