Extracting directories only from tar ball


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Extracting directories only from tar ball
# 1  
Old 09-18-2012
Extracting directories only from tar ball

Hi

Somebody must have done this before, but I can't seem to find any answer on my problem.
On HP-UX 11i v3 I have a relatively large tar ball (~120 GB), and I want to create the directory structure only from the archive.
There is no option to make a new archive with only the directory structure, which would have been the easier way out.

Hope that somone has an answer to this.

Thank you in advance.
# 2  
Old 09-18-2012
This might work (untested):
Code:
tar tf archive.tar | sed 's/\/[^\/]*$//' | sort | uniq | xargs mkdir -p

The sed-call strips the last component from all pathnames (like dirname), sort and uniq eliminate duplicates and the last command creates the directories.

You probably will have to adapt the sequence to your needs.

Last edited by hergp; 09-18-2012 at 04:01 PM.. Reason: typo
This User Gave Thanks to hergp For This Post:
# 3  
Old 09-19-2012
Thank you. I guess it will work as I requested (it's running at the moment).

What I forgot to mention was that I would like to keep the original permissions and ownership, which you don't get with this method.

I've already kept my colleagues busy with this puzzle for hours, and I am still surprised that there's not an easier way Smilie
# 4  
Old 09-19-2012
This is a two step approach, but it should do what you request:
1) create an "exclude file" containing all entries that are NOT directories (hoping your grep installation can use EREs).
2) untar the tarball excluding above; this will create the directories with owner info and permissions:
Code:
tar -ztf arch.tar.gz|grep -E "[^/]$" >excl
tar -zxf arch.tar.gz -X excl

You may need to anchor the result according to your needs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create Tar ball

Hi Team, Following unix command is throwing error. Can anyone please help me to fix the issue? tar -cvf /aa/bb/cc/tarball1.tar /x/y/z1/abc.ksh /x/y/z2/pqr.txt /x/y/z3/lmn.tmp Error message thrown: tar: Removing leading `/' from member names OS: uname -a Linux xyz... (1 Reply)
Discussion started by: kmanivan82
1 Replies

2. Shell Programming and Scripting

Problem creating a tar ball in different directories

Hi all. I'm hitting a problem creating a tar archive in one directory from files located in a different directory. It fails when I replace the absolute paths with variables in the script but works if I just run tar on the cmdln. E.g. #!/bin/ksh BASE=$PWD STAGE=$BASE/stage LOG=$BASE/log... (4 Replies)
Discussion started by: user052009
4 Replies

3. Shell Programming and Scripting

Untar only folder structure from a tar ball

I have a tar file hello.tar which is 95 GB. hello.tar has many files and folders including some tar files as well. I wish to create a new tar ball which should maintain only the folder structure of hello.tar and the tar ball within the hello.tar So basically the idea is to untar... (2 Replies)
Discussion started by: mohtashims
2 Replies

4. Shell Programming and Scripting

Need Tar Ball command to exclude directories

Hi, uname -a SunOS mymac 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise I need to tar a folder /tmp/moht but do not want these three folders to be included in the tar file -> savejpg, bmpsave and imgsave I tried --exclude, -path, -not options but it says bad option Can you help me with... (3 Replies)
Discussion started by: mohtashims
3 Replies

5. Shell Programming and Scripting

Extract a tar ball into multiple directories

#cat a BAC064DAL BAC063DAL BAC056PHX BAC066DAL BAC062PHX BAC062DAL BAC060DAL BAC058PHX BAC054PHX BAC051PHX # for i in `cat a` > do > tar xvf $a/$a*.tar* > done tar: /*.tar*: Cannot open: No such file or directory tar: Error is not recoverable: exiting now tar: /*.tar*: Cannot... (3 Replies)
Discussion started by: kenshinhimura
3 Replies

6. Shell Programming and Scripting

Extract files from tar ball without directory structure

Hi, I have tar filw which has multiple directories which contain files. When i extract using tar -xf the directory structure also get extracted. I require only files and not directory structures as there will be overhead of moving the files again. So i searched here and got a solution but... (4 Replies)
Discussion started by: chetan.c
4 Replies

7. Shell Programming and Scripting

Extract contents of tar ball without extracting files

Hi, I'm using a tar command tar -xOvf /home/mytar.tar My intention is to extract data in files which are inside various directories, without extracting files to the disk. Is this the best way to achieve it? Thanks, Chetan (3 Replies)
Discussion started by: chetan.c
3 Replies

8. UNIX for Advanced & Expert Users

Size of a tarball without untarring - Catch parent tar ball has sub tars

hi, I am in a weird situation. I have a parent tarball which contains 2 sub tarballs. The structure is such : Parent.tar.gz ---- > child1.tar.gz and child2.tar.gz I need to get the size of the parent tarball without untaring it I know that the command is gunzip -c parent.tar.gz | wc -c ... (1 Reply)
Discussion started by: mnanavati
1 Replies

9. Shell Programming and Scripting

Extracting .tar files.

Hey guys complete n00b here so I'll try my best at explaining. I'm creating a backup and restore utility and decided to use tar. I create a backup folder in each user's account and when backing up (say word processing files), I use the following: tar cvf /home/user/backup/wpbackup.tar... (2 Replies)
Discussion started by: EwanD
2 Replies

10. UNIX for Dummies Questions & Answers

error while extracting using TAR

Hi folks, When I am extracting an archive using the: tar -xvf /dev/rmt0 command i get the following error: x ./GRBD8901/GRBR006T, 1763253368 bytes, 3443855 media blocks. tar: 0511-197 ./GRBD8901/GRBR006T: Cannot write data extracted with the tar command: ... (7 Replies)
Discussion started by: Erik Rooijmans
7 Replies
Login or Register to Ask a Question