I tar'd and zip'd the following file:




I was trying to untar and unzip to /opt/abc/xyz/(same path) directory.

I came across the below command. I executed it as the root user, but didn't find any error or output. I am expecting below command will extract abc.xml from abc.xml.tar.gz and renamed to abc.xml_v9.

tar --force-local --transform='s/abc.xml/abc.xml_v9/' -zxpsf /tmp/backup/abc.xml.tar.gz -C /

output should be


man page of tar says below information

File name transformations:      

       --transform=EXPRESSION, --xform=EXPRESSION
              use sed replace EXPRESSION to transform file names

              File name matching options (affect both exclude and include patterns):

Can someone help me understand the above command with some example?

  • 2
    What do you want to achieve and what doesn't work?
    – Cyrus
    Commented Feb 4, 2018 at 8:44
  • @Cyrus i hope now my question is clear to you.
    – user112232
    Commented Feb 4, 2018 at 9:03
  • Add output of tar -tzf /tmp/backup/abc.xml.tar.gz to your question.
    – Cyrus
    Commented Feb 4, 2018 at 9:22

1 Answer 1


Using your example files source /tmp/backup/abc.xml.tar.gz and destination /opt/abc/xyz/abc.xml_v9. you can use thsi command:

tar --transform='flags=r;s|abc.xml|abc.xml_v9|' -xvf abc.xml.tar.gz -C /opt


tar --transform='flags=r;s/abc.xml/abc.xml_v9/' -xvf abc.xml.tar.gz -C /opt

And you will get





  • Additionally, you might want to use the -P/--absolute-names option, otherwise tar removes the leading / prior to transforming, which might hurt your transform pattern. Commented Jun 3, 2020 at 20:45

You must log in to answer this question.

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