LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-21-2006, 11:45 PM   #1
taiwf
Member
 
Registered: Jun 2005
Distribution: debian, ubuntu, redhat,knoppix
Posts: 194

Rep: Reputation: 31
untar a single directory of a large


hi,

I try to extract only 60% of a very large backup tar by using

tar -xvf source_tar_filename first_dir/dest_dir

But after i hit enter i just got a new line and hang there for very long. I wonder if it is the right way to use tar? Is there anyway to properly untar a portion of a large tar file (over 50G)?

Besides, some tutorial say if you put the last parameter as a filename, it will just untar that particular file. But,what happen if you have 2 identical filenames exist in different directory of the tar? Will tar command get confused or it will prompt you for over write?


thx in advance



chris
 
Old 02-22-2006, 02:53 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
tar will simply check every entry in it's archive to see if it matches the pattern you supplied.
If your pattern contains wildcards (* or ?), then you probably want to enclose it in single quotes to prevent the shell from expanding it before passing it to the tar command.
ie
say I have a file 'abc.txt' in the current directory and I want to retrieve all *.txt files from a tar archive.
tar -xvf mytar.tar *.txt will make the shell expand *.txt into "abc.txt" before tar gets to see it. So tar will only look for files that are called "abc.txt" in the archive.
Instead use:
tar -xvf mytar.tar '*.txt'
The single quotes prevent the shell filename expansion.

Secondly, you can put any pattern you like, regardless if it's a directory or just a file.
For instance:
a pattern like '*/*/*.txt' is also allowed and only matches the .txt files that are 3 levels deep.

If you're not sure what you want to extract, do a
Code:
tar -tvf yourtar.tar
first.

tar also extracts the folders by default, which means that no file clobbering can occur.

To extract files/dirs from a large tar, you'll need to be patient. tar was created to read/write on tapes and hence works sequentially. It simply looks through the content list of the entire archive to find any matches of the pattern you specified and will extract all matches found.

If you would put let's say just "abc.txt" (a filename) as last parameter, then tar may extract both
dir1/abc.txt and dir2/abc.txt. But it would create the dir1 and dir2 directories, so you get the 2 extracted files. The first file isn't overwritten by the second one.

Notice also that tar paths are usually relative, unless the -P (or --absolute-names) option was used.

See tar --help for info, especially the section on "local file selection" options.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to untar all tar-files in a directory? zoomzoom Linux - Newbie 13 05-09-2017 11:52 AM
Kernel source directory way too large Ahmed Linux - Software 3 12-28-2005 06:27 AM
tar - extracting a single directory from a large archive? lowpro2k3 Linux - General 1 07-24-2005 02:44 AM
Elegantly moving a large directory. aje Linux - General 2 07-07-2005 09:17 AM
Untar to a directory john8675309 Linux - Software 2 03-14-2004 09:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration