Help with tar/pax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with tar/pax
# 1  
Old 03-26-2012
Help with tar/pax

Hi,

I have tar ball "data.tar" which consists of many files from different directories.

If I untar a file using following command, it will untar file to location /input/data

Code:
 
tar -xvf data.tar /input/data/abc.txt

I want the file to be untar in current directory and or any other directory of my choice. Also it should not overwrite if there is a file with the same name in the directory.

I searched and found that pax command could do it. But could not find the exact command for my need.

I found the following command but looks like the below command will untar all files and not specific file.

Code:
 
pax -dv -f data.tar -s'/directoryname.\///p'

Help is highly appreciated.
# 2  
Old 03-26-2012
I don't use pax very often, but I think this will do what you want:

Code:
pax -s "!.*/!!" -f data.tar -k -r /foo/bar/input.txt

It should extract only input.txt to the current directory, and should not try to create the directory structure (/foo/bar in this case) above it. If you use the 'p' option on the substitution parameter (-s) it will print all of the filenames, not just the ones that match the ones given on the command line. The -k option should issue a warning, and not overwrite the file already on disk, if a file exists.

I used bangs (!) in the substitution parameter as it avoids needing to escape the slant and thus is easier to read.

I also believe you can use a pattern so somethingg like "/foo/bar/*.txt" would pull all .txt files from the archive and place them in the current directory. (Quotes are needed here to prevent glob expansion matching anything in the current driectory.)

Hope this gets you a bit further along.

Last edited by agama; 03-26-2012 at 09:33 PM.. Reason: icode tags :)
# 3  
Old 03-27-2012
Quote:
Originally Posted by agama
I don't use pax very often, but I think this will do what you want:

Code:
pax -s "!.*/!!" -f data.tar -k -r /foo/bar/input.txt

It should extract only input.txt to the current directory, and should not try to create the directory structure (/foo/bar in this case) above it. If you use the 'p' option on the substitution parameter (-s) it will print all of the filenames, not just the ones that match the ones given on the command line. The -k option should issue a warning, and not overwrite the file already on disk, if a file exists.

I used bangs (!) in the substitution parameter as it avoids needing to escape the slant and thus is easier to read.

I also believe you can use a pattern so somethingg like "/foo/bar/*.txt" would pull all .txt files from the archive and place them in the current directory. (Quotes are needed here to prevent glob expansion matching anything in the current driectory.)

Hope this gets you a bit further along.


Thanks agama this works great except a minor change is needed.

Instead of untarring the file in current directory i would like to untar it to any other directory of my choice. What should be the change.

I understood what the command is doing except the following piece.

Code:
 
-s "!.*/!!"

I understand it is replacing the directory path but not completley understand it.

Would appreciate you inputs on this.
# 4  
Old 03-27-2012
If I were writing a script to do this I would cd to the target directory for unload, and then invoke pax. You can put it all in parens (example below) which will eliminate the need to cd back to the original directory:


Code:
( cd /path/to/desired/directory;  pax ......)

The substitute command removes all characters from the front of the string through the last slant so that the directory name is removed. It's the same as this sed expression: s/.*\//. I use bangs (!) so as to avoid needing to escape the slant in the pattern.


Hope these make sense
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help using pax to restore into current directory?

Hello, I have a tape backup (it was made using dd/tar) and I want to use dd/pax to restore tape to disk, in IBM AIX 7.2. I can restore from tape using example below without issues. #/usr/bin/dd bs=128k if=/dev/rmt0 | /usr/bin/pax -r -v /home/c3rb3rus/utils/* USTAR format archive... (6 Replies)
Discussion started by: c3rb3rus
6 Replies

2. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

3. UNIX for Dummies Questions & Answers

Difference between 'pax', 'tar', and cpio

Could any one please help me in understanding the difference between pax,tar and cpio. all of them basically creates archive files. (9 Replies)
Discussion started by: joshi123
9 Replies

4. UNIX for Dummies Questions & Answers

tar/cpio/pax read patterns from stdin

tar has the -T operand for reading patterns from a file. Is there any way to read patterns from stdin, without creating a temp file? I would like to avoid iterating over the archive repeatedly (e.g. with a loop or xargs) as this is a large archive and we're only extracting a small number of... (2 Replies)
Discussion started by: uiop44
2 Replies

5. Shell Programming and Scripting

pax me out

hi I am using this command pax -f /Unix/codes/code.tar -r -s::/Unix/archive: objective is to transfer tar file /Unix/codes/code.tar to /Unix/archive with untarring done . For this reason i am using pax and not tar -xvf as we cant specify untarred destination in that the problem is... (2 Replies)
Discussion started by: ultimatix
2 Replies

6. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

7. UNIX for Advanced & Expert Users

pax help

we created a TAR file ( souce /opt/oracle/10.2) . If we want to extract it diff directory say (/tmp) . I know we can use pax to do this .but inside TAR we have absolute path ref . if we pax does it replaces absolute path in TAR ? Thanks (1 Reply)
Discussion started by: talashil
1 Replies

8. AIX

PAX error on retrieving from tape

Hi, I am using AIX 5.3.0.0 and Ultrium LTO3 Tape Drive as rmt1. I have backup some of my database file using command "pax" as pax -wvf /dev/rmt1 "./data01/abc.dmp" But when I tried to read the file from tape by issuing the command, pax -vf /dev/rmt1 The error message displayed as pax:... (4 Replies)
Discussion started by: kwliew999
4 Replies

9. UNIX for Dummies Questions & Answers

Solaris and PAX

I am having trouble with the pax command on Saris. I want to sue it to untar a file to a different directory. So if mytar.tar conatins files that were in /u02/mydir/mydir2/mydir3, I want to untar them to /export/home/mydir. An example I have is: pax -r -s... (2 Replies)
Discussion started by: hshapiro
2 Replies

10. UNIX for Dummies Questions & Answers

how to retain text using pax

I have a .tar file consisting of text and binary files. I ftp'd the .tar file using ftp binary. when I did the pax to unwind the tar file, I noiticed that the text files were encoded in binary. **How would I retain the text characteristics of the ascii text files, while also keeping the... (11 Replies)
Discussion started by: idic5
11 Replies
Login or Register to Ask a Question