Problem :
I have 20 files(txt files) under the folder:
/a1/a2/a3/
e.g /a1/a2/a3/abc.txt , /a1/a2/a3/abcd.txt , etc
I want them to tar+gzip them individually to folder
/a1/b1/b2/b3
Also I want to create a final tar of all those files in the folder (
/a1/b2/b2/) and name it as "final.tar"
My Attempt :
Code:
for file in /a1/a2/a3/*
do
file1='echo $file | awk -F'/' '{print $5}' # get filename
tar -cvzf /a1/b1/b2/b3/$file1".tar.gz" /a1/a2/a3/$file1
done
tar -cvf /a1/b1/b2/"final.tar" /a1/b1/b2/b3
final.tar is succesfully created.
Problem :
When I untar the final.tar file to get the individual tar+gzip files using :
a folder is created inside the target foilder and all the 20 files(tar+gzipped) are found in the directory
/a1/b1/b2/a1/a2/a3/
So new directory structure is created inside the target folder. Which I dont want.
Help Needed.