Maybe this will help a little.
Lets say you have three directories in
/usr/local;
/usr/local/dirA,
/usr/local/dirB and
/usr/local/dirC. You want to create three separate tar archives of the content of those directories.
If you're working in your home directory, say,
/home/yours and do this
Code:
/home/yours: tar czf dirA.tar.gz /usr/local/dirA
/home/yours: tar czf dirB.tar.gz /usr/local/dirB
/home/yours: tar czf dirC.tar.gz /usr/local/dirC
You would wind up with
Code:
/home/yours: ls *.tar.gz
dirA.tar.gz dirB.tar.gz dirC.tar.gz
The conents of each of those would have the leading / stripped off and, for example,
dirA.tar.gz's contents would look like
Code:
usr/local/libA/file.name
You can retain the leading / with the
-P option (so
czPf rather than
czf).
That's all well and good if you want to restore an archive to it's original location; however, if you want to extract the contents of the archive somewhere else, it's better to
Code:
cd /usr/local
tar czf dirA.tar.gz dirA
tar czf dirB.tar.gz dirB
tar czf dirC.tar.gz dirC
so you can change directory to wherever you want (and, you know, can write to) and extract the content of each archive; the directories (
dirA,
dirB and
dirC) will be created when
tar extracts. Note, too, that you do not want the
P in this case.
It's generally easier to do things a step at time rather than all in one go if for no other reason than you have a chance to think about what you're trying to, eh?
Hope this helps some.