Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-05-2009
Registered User
 

Join Date: Dec 2009
Location: Scotland.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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:


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

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


Code:
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
Sponsored Links
  #2  
Old 12-05-2009
Registered User
 

Join Date: May 2008
Location: Tucker GA
Posts: 111
Thanks: 0
Thanked 2 Times in 2 Posts
Sounds like you are sitting in the backup directory when you extract. Tar will extract to wherever you are.

cd /
tar xvf /.......
  #3  
Old 12-05-2009
scottn's Avatar
scottn scottn is online now Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 2,593
Thanks: 13
Thanked 91 Times in 88 Posts
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"
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extracting data from files.. anchal_khare Shell Programming and Scripting 1 04-03-2008 06:56 AM
extracting files using date in ksh pavan_test UNIX for Dummies Questions & Answers 1 04-04-2006 03:29 PM
Is extracting specific files from a zip file possible? HLee1981 UNIX for Dummies Questions & Answers 1 10-14-2005 11:06 PM
Extracting values from files Master Error Shell Programming and Scripting 4 08-15-2004 09:23 AM
extracting .rar files sskb UNIX for Dummies Questions & Answers 5 05-15-2002 09:20 PM



All times are GMT -4. The time now is 07:49 AM.