LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-03-2012, 07:29 AM   #1
prtzy
LQ Newbie
 
Registered: Oct 2012
Posts: 1

Rep: Reputation: Disabled
Exclamation 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.
 
Old 10-03-2012, 07:33 AM   #2
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,557

Rep: Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761
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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] unzip / untar one specific file or (sub)folder dragonetti Linux - Newbie 8 09-21-2011 05:09 AM
untar to a specific folder kennmurrah Linux - General 4 05-22-2010 06:06 AM
How to Move Unwanted messages From Mailq to Diffrent Folder manusys Linux - Newbie 3 04-08-2010 07:01 AM
Why can't I untar from inside folder where the tarbell is? newbiesforever Linux - General 5 07-17-2009 10:54 PM
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration