Nothing stupid about them...

...I just stole the name from David Letterman's "stupid pet tricks". I hope these tips help you avoid or fix mistakes along the way in your *nix administration duties.

Saturday, March 22, 2008

Be careful of Solaris' tar command!

When creating a tar file in Solaris, NEVER use a leading slash in the target:

tar cvf mytarfile.tar /etc


...because when you untar it on your destination, regardless of the present directory, it will overwrite everything in /etc! What a way to spoil your day. Always, always use relative path targets for Solaris' tar.

cd /etc
tar cvf mytarfile.tar .


Get in the habit of always displaying the tar file's contents first:

tar tvf mytarfile.tar


...and never unpack it if it begins with a slash!

If you have such a tar file, what do you do now?

/usr/bin/cp /usr/sbin/static/tar /tmp
/usr/bin/dd if=file.tar | /usr/bin/chroot /tmp ./tar xf -


...and your output will be safely unpacked in /tmp. Yes, you have to be that anal about it.

Fortunately, this is not a problem with GNU tar in Linux and other OS's; the path is always relative. But you could still muck up things if you are in / when you unpack!

Be careful out there.

2 comments:

Kevster! said...

Wow. That was handy! Exactly what I needed. Thanks!

Swathi said...

good article. For more examples on tar command:tar command examples in unix

Search

Google