Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-03-2012, 07:29 AM   #1
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:


e.g /a1/a2/a3/abc.txt , /a1/a2/a3/abcd.txt , etc

I want them to tar+gzip them individually to folder


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 :

for file in /a1/a2/a3/*
    file1='echo $file | awk -F'/' '{print $5}'   # get filename
    tar -cvzf /a1/b1/b2/b3/$file1".tar.gz" /a1/a2/a3/$file1

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 :

tar -xvf final.tar
a folder is created inside the target foilder and all the 20 files(tar+gzipped) are found in the directory

So new directory structure is created inside the target folder. Which I dont want.
Help Needed.
Old 10-03-2012, 07:33 AM   #2
Senior Member
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,188

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:02 AM.

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