Hi.
Here's a short example of tar using relative paths, e.g. ".", and changing to a directory with "-C":
Code:
#!/bin/sh
# @(#) s1 Demonstrate tar with relative paths in different directories.
DIRS="./d1 ./d1/d2"
# Remove debris from previous runs, create fresh test files.
rm -rf d1
mkdir -p $DIRS
touch d1/d2/file1 d1/d2/file2
echo
echo " Contents of test directory:"
ls -FR d1
echo
echo " Tell tar to Change to a directory and tar from \".\""
echo
tar cvf my-tar -C d1/d2 .
echo
echo " Contents of tar:"
echo
tar tvf my-tar
exit 0
which produces:
Code:
% ./s1
Contents of test directory:
d1:
d2/
d1/d2:
file1
file2
Tell tar to Change to a directory and tar from "."
./
./file1
./file2
Contents of tar:
drwxr-xr-x makyo/makyo 0 2007-05-20 09:08:57 ./
-rw-r--r-- makyo/makyo 0 2007-05-20 09:08:57 ./file1
-rw-r--r-- makyo/makyo 0 2007-05-20 09:08:57 ./file2
Note well that the final parameter on the tar is a dot.
If you want the directory name, e.g. "./d2/file1", provide the path to "-C" one level up: "-C d1".
See
man tar and
info tar for details. Best wishes ... cheers, makyo
( edit 1: add, clarify )