Extracting .tar files.

Hey guys complete n00b here so I'll try my best at explaining.

I'm creating a backup and restore utility and decided to use tar. I create a backup folder in each user's account and when backing up (say word processing files), I use the following:

 tar cvf /home/user/backup/wpbackup.tar /home/user/wp/*

When I go to extract, though, I'm using the following command:

tar xvf /home/user/backup/wpbackup.tar

Problem is that this creates a /home/user/wp/ path IN the backup directory, as well as extracting the files in there. What I would like to know is how to fix this so that the extracted files from wpbackup.tar are put back into the /home/user/wp/ directory.

That's my primary aim^, however if I can't get that working is there any way to extract the contents of the tar file into the directory it was created in (/backup), so I can just copy them across to the user's appropriate directory?

Cheers for any help,

Ewan

Sounds like you are sitting in the backup directory when you extract. Tar will extract to wherever you are.

cd /
tar xvf /.......

I would say more likely is that tar is extracting using the full path.

It is in most cases better to tar things up using relative paths.

Then you can untar it wherever you like.

---------- Post updated at 06:40 PM ---------- Previous update was at 06:32 PM ----------

The BSD tar on my Mac contradicts what I just said, but on Solaris and AIX (and I think probably HP-UX), it's accurate enough.

The Solaris man page says "Absolute path names contained in the archive are unpacked using the absolute path names, that is, the leading forward slash (/) is not stripped off"