BW-userx |
07-08-2019 11:17 AM |
bash: script to tar up a bunch of sub-dir separately
first time trying this in a script, and in succession, so I am lacking in understanding how tar actually works in that situation.
my script
Code:
#!/bin/bash
#set -xv
#read -p "Enter Working Dir path. " path
path="/run/media/userx/1TB/Adam & The Ants"
cd "$path"
echo $(pwd)
#get all sub dir in parent dir to tar up separately
mapfile -t tars < <(find . -type d)
to="${path%/*}/JustCreated-Tars-Gzs"
mkdir -pv "$to"
for i in ${tars[@]} ;
do
#remove leading ./
targz="${i#*/}".tar.gz
tardir="${i#*/}"
tar -zcvf "$targz" "$tardir"
mv -v "$targz" "$to"
echo "NEXT"
echo;echo;echo;echo
unset targz
unset tardir
exit
done
it does not even tar one sub dir then exit. It just keeps going tarting all of them into one, and then changes its name.
part of the output as it is a too much to post.
Code:
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/8. A.N.T.S. [Unreleased].mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/21. Friend Or Foe [Single].mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/14. Friend Or Foe (Alt. Version).mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/4. Killer In The Home.mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/20. Man Called Marco.mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/19. Desperate But Not Serious [Single].mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/6. Magnificent Five (Alternate Mix).mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/18. Zydyco [Unreleased].mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/CD2/13. Stand And Deliver [Single].mp3
./2001 Adam & The Ants - AntBox [The Definitive Story]/Adam & The Ants - AntBox [The Definitive Story] Back.jpg
tar: .: file changed as we read it
renamed '..tar.gz' -> '/run/media/userx/1TB/JustCreated-Tars-Gzs/..tar.gz'
then the last it changes the name from what is suppose to be the sub dir name to that ..tar.gz When it is suppose to be each sub dir in its own tar file.
|