Visit Our UNIX and Linux User Community


Extract files from tar ball without directory structure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract files from tar ball without directory structure
# 1  
Old 05-01-2012
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 i'm not able to understand what its doing.I've read the man pages but not able to get.
The Solution is like this.
Code:
pax -r -f tartest.tar -s'/tartest\///'

Please guide me to understand what its doing and what
Quote:
\///'
means?.

Thanks,
Chetan.C
# 2  
Old 05-01-2012
It doesn't remove all the path information. It just gets rid of the /tartest/.

It's a regular expression. It replaces tartest/ with nothing.

The backslashes are to get literal /'s into a string delimited with /'s.
# 3  
Old 05-02-2012
Hi Corona,

Thanks.
So if i have the directoy structure in tar like below

Code:
/Folder1/Folder1.1/File1.txt
/folder2/Folder2.1/File2.txt

How can i use it to extract the files directly?


Thanks,
Chetan.C

Last edited by Scrutinizer; 05-02-2012 at 06:39 AM.. Reason: code tags
# 4  
Old 05-02-2012
Hi.
Code:
       --strip, --strip-components N
              Strips the first N components from archive members' pathnames
              when unpacking.

-- excerpt from GNU man tar, q.v.

The full manual is available at GNU tar manual - GNU Project - Free Software Foundation (FSF)

Best wishes ... cheers, drl
# 5  
Old 05-02-2012
@chetan.c
What Operating System and version you have?

The long-term solution is to create your tar archives with relative paths.


When reading a tar archive with pax the simplest is to remove the leading solidus from the absolute filenames. Always practice your tar and pax commands with a small and expendable file before moving on to live data.
Code:
pax -r -f tartest.tar -s '/^\///'


Previous Thread | Next Thread
Test Your Knowledge in Computers #817
Difficulty: Medium
In CSS, E[foo="bar"] matches an E element whose "foo" attribute value is exactly equal to "bar".
True or False?

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. UNIX for Advanced & Expert Users

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... (3 Replies)
Discussion started by: hpvm_adm
3 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 Dummies Questions & Answers

create tar archive without preserving directory structure?

I am adding some individual files to a tar archive and would like them to be added to the archive without any directory hierarchy, even though the files themselves exist in levels of hierarchy. Unfortunately, tar seems to always preserve the directory hierarchy when it adds the files. Here is... (2 Replies)
Discussion started by: Special_K
2 Replies

9. UNIX for Dummies Questions & Answers

extract tar files without creating directory

I received a tar file of a directory with 50,000 files in it. Is it possible to extract the files in the tar file without first creating the directory? ie. Doing tar -xvf filename.tar extracts as follows: x directory/file1.txt x directory/file2.txt . . . I would like to avoid... (4 Replies)
Discussion started by: here2learn
4 Replies

10. UNIX for Advanced & Expert Users

MV files from one directory structure(multiple level) to other directory structure

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies

Featured Tech Videos