Extracting .tar files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting .tar files.
# 1  
Old 12-05-2009
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
# 2  
Old 12-05-2009
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
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"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 files tar.lzo with/without extracting

Hi Guys, I have 2 compressed files tar.lzo and having many subdirectories inside it. I would like to know which files having the difference in terms of size/content. I am using bash shell and unix server example:- file1 :- abc.tar.lzo file2 :- xyz.tar.lzo Result:- ... (4 Replies)
Discussion started by: himanshupant
4 Replies

2. UNIX for Beginners Questions & Answers

Linux read specific content file from tar.gz files without extracting

hello i wish to write the result of these below conditions in a file: 1. in a specific folder, i have many tar.gz files. 2. each tar.gz file contains ".dat" file in sub folders. 3. i wish to get the full path of these .dat files, if i find in it a specific word ("ERROR24"). 4. all this... (6 Replies)
Discussion started by: jimmyjames9
6 Replies

3. Shell Programming and Scripting

Bash not removing all .tar.bz2 files after extracting

In the bash below each .tar.bz2 (usually 2) are extracted and then the original .tar.bz2 is removed. However, only one (presumably the first extracted) is being removed, however both are extracted. I am not sure why this is? Thank you :). tar.bz2 folders in /home/cmccabe/Desktop/NGS/API ... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Extracting .tar.gz files

I have a directory tree containing archive .tar.gz files that I want to extract at the location where they recide. How can I achieve such an operation? (7 Replies)
Discussion started by: kristinu
7 Replies

5. Shell Programming and Scripting

Extract contents of tar ball without extracting files

Hi, I'm using a tar command tar -xOvf /home/mytar.tar My intention is to extract data in files which are inside various directories, without extracting files to the disk. Is this the best way to achieve it? Thanks, Chetan (3 Replies)
Discussion started by: chetan.c
3 Replies

6. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

7. UNIX for Advanced & Expert Users

extracting multuiple tar files with while and read

Is anyone out there? I'm trying to run a script i wrote that extracts multiple .tar files in succession by pasting it into standard input. It does extract them all but I cant get it to stop looping and when I hit enter I get a tar command error like its still looking for files to extract. ie; ... (2 Replies)
Discussion started by: commoja
2 Replies

8. UNIX for Dummies Questions & Answers

Extracting specific files from a tar file in HP-UX

I have tried: tar -xfv mytarfile.tar archive/tabv/* tar -xfv mytarfile.tar --wildcards 'archive/tabv/*' tar -xf mytarfile.tar -v --wildcards 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards --no-anchored 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards `archive/tabv/*` and none... (5 Replies)
Discussion started by: zapper222
5 Replies

9. Shell Programming and Scripting

bash - batch script for extracting one file from multiple tar files

so i have hundreds of files named history.20071112.tar (history.YYYYMMDD.tar) and im looking to extract one file out of each archive called status_YYYYMMDDHH:MM.lis here is what i have so far: for FILE in `cat dirlist` do tar xvf $FILE ./status_* done dirlist is a text... (4 Replies)
Discussion started by: kuliksco
4 Replies

10. UNIX for Dummies Questions & Answers

error while extracting using TAR

Hi folks, When I am extracting an archive using the: tar -xvf /dev/rmt0 command i get the following error: x ./GRBD8901/GRBR006T, 1763253368 bytes, 3443855 media blocks. tar: 0511-197 ./GRBD8901/GRBR006T: Cannot write data extracted with the tar command: ... (7 Replies)
Discussion started by: Erik Rooijmans
7 Replies
Login or Register to Ask a Question