LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unwanted folder structure created while UNTAR (https://www.linuxquestions.org/questions/linux-newbie-8/unwanted-folder-structure-created-while-untar-4175430265/)

prtzy 10-03-2012 07:29 AM

Unwanted folder structure created while UNTAR
 
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 :

Code:

tar -xvf final.tar
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.

ruario 10-03-2012 07:33 AM

Either switch directories when you add with '-C' or look at the '--strip' option to remove as many elements from the path as you like (assuming GNU tar).


All times are GMT -5. The time now is 10:13 PM.