I have a tar.gz called "first.tar.gz". Inside it I have only one folder called "first" (no other folders or files). I want to decompress the tar.gz, so the folder "first" renames to "second".

I tried this:

tar -zxf first.tar.gz --transform s/first/second/

but it didn't work for me. I didn't get any errors / response, it just extracted the "first" folder without renaming. The version of tar is 1.26

  • What is the output of tar -ztf first.tar.gz? Nov 7, 2022 at 9:38
  • The output is first/
    – user548208
    Nov 7, 2022 at 9:41
  • I created a file that gives the same output from tar -ztf. Your --transform works in tar 1.30. Nov 7, 2022 at 9:43
  • You accepted an answer that does not solve the described problem. If it solves your problem then it means the current state of the question does not really reflect the problem. "I tried tar -zxf …" should be "I tried tar -vzxf …" and "it just extracted" should be "it printed". Then the answer would fit. Nov 7, 2022 at 10:28

1 Answer 1


When you use --transform with GNU tar and ask for verbose output with -v, the pathnames you see outputted are the un-transformed pathnames.

GNU tar will transform the pathnames according to your --transform expression but will not report these in the output unless you use the option --show-transformed-names.


$ tree
`-- archive.tar

0 directories, 1 file
$ gtar -t -f archive.tar
$ gtar -xv -f archive.tar --transform='s/first/second/'

Note how the above command reports the pathnames stored in the archive. Below, we see that the pathnames were transformed appropriately.

$ tree
|-- archive.tar
`-- second
    `-- dir
        |-- file
        `-- first.txt

2 directories, 3 files

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .