Shell Script
#!/bin/bash
list=`find /home/linoxide/ -type f -name “*.rar”`
for line in $list; do
DEST=${line%/*}
unrar x $line $DEST
done
Shell Script Output
Server1:~$ ./rar.shUNRAR 3.93 freeware Copyright (c) 1993-2010 Alexander RoshalExtracting from /home/linoxide/Dropbox/Yevhen/test.rarExtracting /home/linoxide/Dropbox/Yevhen/wget.sh OK
All OKUNRAR 3.93 freeware Copyright (c) 1993-2010 Alexander RoshalExtracting from /home/linoxide/Pictures/test.rarExtracting /home/linoxide/Pictures/wget.sh OK
All OK
Learning above shell script
#this line must be in every bash script, just ensure that you use correct path
list=`find /home/linoxide/ -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.
No comments:
Post a Comment