Tip of the day: pax and removal of leading slashes

This came up at dayjob a couple of weeks ago and again today.

A nice feature of GNU tar is the removal of leading slashes in an archive. For instance if an archive foobar.tar contains files /foo and /bar the following command in a GNU Linux system:

cp foobar.tar /test
cd /test
tar xvf foobar.tar

Will generate /test/foo and /test/bar. Not so with a Solaris 10 system, where the files will be placed in the root directory.

Thanksfully there is a trivial workaround to remove the leading slash:

pax -rv -s ',^/,,' -f foobar.tar

A workaround now documented in a convenient place, rather than me having to search for it in either the bash history of a random system or an interesting but rather lengthy manpage.

Advertisements

Tags: , ,

One Response to “Tip of the day: pax and removal of leading slashes”

  1. Jenny Cruz Says:

    nice tip there..great timing as i’m creating a script now..thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: