Mostly Linux & Python syntax notes and hyperlinks.

Wednesday, August 19, 2009

selective extraction from tar files using pax

I put all the changes I had to make into a single tar file. The tar program removed the leading '/'s from two of the files. I wanted to extract them without creating an entire directory structure. I found this:

http://www.unix.com/unix-dummies-questions-answers/15182-extract-tar-files-without-creating-directory.html

which led me to pax.

I found I could do what I wanted here with three options:

pax -r -i -f [archive] [pattern_matching_desired_file]

The -r is for read from an archive.
The -f is to give it the name of the archive file.
The -i is for name the pulled out file interactively. This meant I had to rename the file, which allowed me to leave out the parent directories.

(There are many more options on the man page, of course!)


Here's how to pull a file out of a tar without having to create all the subdirectories:
$ls
mychanges.tar
$ tar -tvf mychanges.tar
-rw-rw-r-- sam/zac 193 2009-05-18 06:02:23 dir1/changed1.c
-rw-r--r-- sam/zac 3708 2009-05-18 05:57:05 dir2/changed2.py
-rwxr-x--x sam/zac 9708 2009-05-18 05:51:34 dir3/dir4/dir5/dir6/changed3.ksh
-rw-rw-r-- sam/zac 2282 2009-05-18 05:54:57 dir3/dir4/dir5/dir6/dir7/dir8/dir9/cpx.cfg
To pull out the changed3.ksh without creating its parent directories:
$ pax -r -i -f mychanges.tar *.ksh

ATTENTION: pax interactive file rename operation.
-rwxr-x--x May 18 05:51 dir3/dir4/dir5/dir6/changed3.ksh
Input new name, or a "." to keep the old name, or a "return" to skip this file.
Input > changed3here.ksh
Processing continues, name changed to: changed3here.ksh
Now you have your file in the current directory.
$ ls
changed3here.ksh mychanges.tar

To pull out another:
$pax -r -i -f mychanges.tar *cpx.cfg

ATTENTION: pax interactive file rename operation.
-rw-rw-r-- May 18 05:54 dir3/dir4/dir5/dir6/dir7/dir8/dir9/cpx.cfg
Input new name, or a "." to keep the old name, or a "return" to skip this file.
Input > cpx.cfg
Processing continues, name changed to: cpx.cfg
And there it is:
$ ls
cpx.cfg changed3here.ksh mychanges.tar

No comments:

Post a Comment