If I have a tar.gz archive containing a single folder named like <somename>-<somenumber>
, how do I extract it so it unpacks into a folder called <somename>
?
For example, the file somearchive.tar.gz
contains a top-level folder somearchive-0.1.2
, and I tried something like:
tar xvfz somearchive.tar.gz --transform s/[a-zA-Z]+\-[0-9\.]+/somearchive/
but that extracts it to the default folder.
--transform
option expects a GNU basic regular expression I think - so you need to backslash escape the+
in order to make it a quantifier. Try--transform 's/[a-zA-Z]\+-[0-9.]\+/somearchive/'
(-
doesn't need escaping, and.
doesn't when inside[]
)somename -> somename-somenumber
. That way you can easily rollback if needed. If that is not an issue, see unix.stackexchange.com/a/535763/364705