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

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?

What do some sample filenames look like:

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:

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.

1 Like

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.

@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.

Hi, I run on Solaris 10 X86.