GNU tar lives on featuritis, so naturally also has some options for that.
http://www.gnu.org/software/tar/manual/html_node/transform.html
If you just want to remove a few path segments, then --strip-components=n
or --strip=n
will often do:
tar xvzf tgz --strip=1
But it's also possible to regex-rewrite the files to be extracted (flags are --transform
or --xform
and accept ereg with the /x
modifer):
tar xvzf tgz --xform='s#^[^/]+#.#x'
# or 's#^.+/##x' for discarding all paths
For listing a tar you need the additional --show-transformed
option:
tar tvzf tgz --show-transformed --strip=1 --xform='s/abc/xyz/x'
I believe the rewriting options also work for packing, not just for extracting. But pax
has obviously a nicer syntax.