relative pathname question!

Michael Greim greim at sbsvax.UUCP
Wed Aug 10 19:59:38 AEST 1988


In <5762 at super.upenn.edu> Joel Spolsky writes:
>In article <1670003 at hpcilzb.HP.COM> tedj at hpcilzb.HP.COM (Ted Johnson) writes:
>>
>>I read the manual (really!), but I still can't figure out how
>>to copy everything from a directory onto a tape (with either
>>tar or cpio) USING RELATIVE PATHNAMES (as contrasted to absolute
>>pathnames).
>
>Set your default directory using "cd" and just use 
>
>tar cf /dev/whatever *
>
>This will store all the files in the current directory with relative
>pathnames and not absolute ones.

>As far as I can tell, there is NO way to extract tar files with
>absolute pathnames anywhere except their original positions.
There is a way. Here it is:

------- cut here ----------------------------------------------------
static char * sccsid = "@(#)  tarfix.c  (v1.1 2/8/88)";
/*
 * this nifty program is by 
 * Phil Hochstetler
 * Sequent Computer Systems
 * Beaverton, Oregon
 *
 * it prevents tar from using absolute pathnames
 */

# include <stdio.h>

main()
{
	char fixbuf[512];

	if (isatty (0)) {
		fprintf (stderr, "tarfix by Phil Hochstetler\n");
		fprintf (stderr, "proposed usage (MX2) :\n");
		fprintf (stderr, "tarfix < /dev/fl2 | tar -XXf -\n");
		fprintf (stderr, "instead of XX use your own options\n");
		exit (0);
	}
	while (read(0, fixbuf, sizeof (fixbuf)) == sizeof (fixbuf)) {
		if (fixbuf[0] == '/' && fixbuf[99] == 0) {
			strcpy(fixbuf, &fixbuf[1]);
			fixbuf[99] = '/';
		}
		write(1, fixbuf, sizeof (fixbuf));
	}
	exit (0);
}
------- cut here -----------------------------------
This program should be used in a pipe. It reads the tar blocks
and deletes a leading "/" in a pathname so if you have
/a/b/c it will be created in ${cwd}/a/b/c. As relativ as you can get.
If you want it somewhere else you could then copy it, or indeed you
could change the above program to change certain pathnames to certain
other pathnames.
On my machine (MX2), tar for diskettes is called "far".

Absorb, apply and enjoy,
	-mg
-- 
+------------------------------------------------------------------------------+
| UUCP:  ...!uunet!unido!sbsvax!greim   | Michael T. Greim                     |
|        or greim at sbsvax.UUCP           | Universitaet des Saarlandes          |
| CSNET: greim%sbsvax.uucp at Germany.CSnet| FB 10 - Informatik (Dept. of CS)     |
| ARPA:  greim%sbsvax.uucp at uunet.UU.NET | Bau 36, Im Stadtwald 15              |
| Phone: +49 681 302 2434               | D-6600 Saarbruecken 11, West Germany |
+------------------------------------------------------------------------------+
| # include <disclaimers/std.h>                                                |
+------------------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list