Extract particular folder from a .tar format files.

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Extract particular folder from a .tar format files.
# 1  
Old 02-25-2011
Extract particular folder from a .tar format files.

Hi All-
I want to extract a particular folder from .tar format files.

For example:
File Name: backup.tar
The backup.tar contains the below folders & files.
1) /root_folder/Folder1/Folder1-1/*
2) /root_folder/Folder1/Folder1-2/*
3) /root_folder/Folder2/Folder2-1/*
4) /root_folder/Folder2/Folder2-2/*
The “tar -xf” command extract 1 to 4 item. But I want to extract ‘Folder1' and their tree only ( 1 - 2 only). Please help me the command.

Thanks
Mani Muthu
# 2  
Old 02-25-2011
What Operating System and version you you have?
What Shell do you use?

Do you have the "pax" command? It's a program which can read "tar" archives.

What was the command used to create the "tar" archive?

How large is the archive, and how many different files need to be restored?
Quote:
ls -ald backup.tar
What do some sample filenames look like:
Quote:
tar -tf backup.tar
Do you know that if the archive was created with absolute pathnames you can only restore to exactly the same directory with "tar"?

Why so many questions you may ask? Restoring from a "tar" archive is inherantly dangerous.


The generic answer based on what we know so far is:
Code:
tar -xvf backup.tar '/root_folder/Folder1/Folder1-2'

Do test the command syntax in a test server with expendable files and be aware that the target folder and subfolders will be overwritten.
This User Gave Thanks to methyl For This Post:
# 3  
Old 03-05-2011
MySQL

Hi There,

#tar -xvf <file_name.tar> . extracts all the contents to the present working location.

To exctract one particular folder, which means you want to exclude the rest of the files/folders, Try the below,

#cat >> /exclude
/root_folder/Folder1/Folder1-2/*
/root_folder/Folder2/Folder2-1/*
/root_folder/Folder2/Folder2-2/
Crtl+d, enter

Now run, #tar -Xxvf /exclude <file_name>

This should work.
# 4  
Old 03-18-2011
@solaris040
What Operating System are you running? Do you have some sort of enhanced "tar"?
# 5  
Old 03-18-2011
Quote:
Originally Posted by methyl
@solaris040
What Operating System are you running? Do you have some sort of enhanced "tar"?
More importantly, what 'tar' do you have? For example, nothing is stopping you from running GNU tar on a Solaris-kernel system. Nothing prevents you from writing or modifying your own tar command and installing it.
# 6  
Old 03-20-2011
Hi, I run on Solaris 10 X86.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

2. Shell Programming and Scripting

Extract files from tar ball without directory structure

Hi, I have tar filw which has multiple directories which contain files. When i extract using tar -xf the directory structure also get extracted. I require only files and not directory structures as there will be overhead of moving the files again. So i searched here and got a solution but... (4 Replies)
Discussion started by: chetan.c
4 Replies

3. Shell Programming and Scripting

Backup files in tar format

Hi, I need backup all the files(including sub directories files ) which we modified today and create the tar file with the filename_<current_date>.tar Thanks (1 Reply)
Discussion started by: gavemani
1 Replies

4. Solaris

How to extract files from a tar file without creating the directories?

Hello all. I have a tar file that contains a number of files that are stored in different directories. If I extract this tar file with -xvf , the directories get created. Is there a way to extract all of the files into one directory without creating the directories stored in the tar file. (9 Replies)
Discussion started by: gkb
9 Replies

5. UNIX for Advanced & Expert Users

UNIX: Command to compress folder and all files into a tar

I am trying to grab a folder and all the folders and files underneath it and send it from one computer to another. I basically want to compress the whole folder into a tar, tgz, or zip file so that it can be sent as one file. is there a command to compress a folder and all its contents into a tar... (7 Replies)
Discussion started by: kane4355
7 Replies

6. Solaris

extract tar.gz under a specific folder

Hi, How to extract a tar.gz file and put it under a designated folder that I specify in a one line command? thank you in advance. (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

7. UNIX for Advanced & Expert Users

How to extract a particular file in tar.Z format

Hi , I need to extarct only a particulay files from the tar.Z. ie i need to extract one.txt from test.tar.Z. The test.tar.Z may contain lot of file and folders. Please help me to extract particular file to some location. Regards, Kalai. (1 Reply)
Discussion started by: kalpeer
1 Replies

8. UNIX for Dummies Questions & Answers

extract tar files without creating directory

I received a tar file of a directory with 50,000 files in it. Is it possible to extract the files in the tar file without first creating the directory? ie. Doing tar -xvf filename.tar extracts as follows: x directory/file1.txt x directory/file2.txt . . . I would like to avoid... (4 Replies)
Discussion started by: here2learn
4 Replies

9. UNIX for Dummies Questions & Answers

extract tar.gz files

Hi All, I want to extract my *.tar.gz files like below; 01.tar.gz 02.tar.gz 03.tar.gz 04.tar.gz 05.tar.gz 06.tar.gz .. .. 31.tar.gz how can I do it by automatically using a command ?? thanks Alice (5 Replies)
Discussion started by: alisevA3
5 Replies

10. UNIX for Dummies Questions & Answers

cant extract files from a tar file

hi everyone i have a tar file which was in AIX box. its 300mb. i cant untar in windowsxp home. I just get an empty folder with no files when i extract. i dont get any bad header or any such error. i am using IZARC which is a freeware. Not sure if i should try winzip or winrar. any help (2 Replies)
Discussion started by: bryan
2 Replies
Login or Register to Ask a Question