Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TAR file: extracting files from an absolute path

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
I have a Solaris 8 tar file containing files with prefixes all starting with /opt/somedir/blahblah... But unfortunately I can't extract the blahblah files to another workstation because I don't have root access to the /opt/ directory...and I can't temporary create /opt/somedir/.

Is there a way to extract the files and in effect ignore the leading /opt/somedir directory?

HISTORY:
Basically, what happen was that I needed to back-up my entire home directory (/opt/somedir/....) to copy to a new box. But the new box's "home" directory structure is setup a little differently compared to the older box-- it's now /export/home/somedir.

Can I use the arch cmd? How in an extract?

Yes, I know I should of been a little more careful by first cding to the /opt/somedir/ directory before creating the tar file!

Thanks ...
 
You might have to take a look at '/usr/sbin/static/tar' and 'man chroot'


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
In some installation the chroot can only be executed from super-user.

Here is an alternative (may be slow because it extracts file by file from the tar file):

#!/bin/ksh
tar tvf myOptFiles.tar |awk '{print $8;}' >tarlist1
sed &quot;s/opt\/somedir/export\/home\/somedir/&quot; tarlist1 |
paste -d' ' - tarlist1 >tarlist2
while read nf tf
do
if [[ &quot;${tf%%*/}&quot; == &quot;&quot; ]]
then
mkdir $nf
else
tar xvf myOptFiles.tar $tf >$nf
fi
done <tarlist2

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
as I mentioned on thread80-642192

tar -xvA tarfile

&quot;A&quot; option if available in Solaris will remove the absolute pathname, and extract to the current directory.
If not available then do a &quot;man tar&quot; to see which one will be





Regards

Frederico Fonseca
SysSoft Integrated Ltd
 

Sorry,

-A option not availabe on Solaris 5.8





----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
You may consider gnu tar.

Hope This Help
PH.
 
I did say to do a &quot;man tar&quot;.

from the manual

option P (uppercase)

Suppress the addition of a trailing &quot;/&quot; on directory entries in the archive.

Now unfortunatelly this only applies to &quot;creating&quot; the archive, not to extract from it, so no good.

You have two options.
1- Recreate the backup file on the original computer
2- Do as PHV sugested and get another tar program (gnu or other) to do the restore.




Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top