tarの--transformパラメータを使用するには?

tarの--transformパラメータを使用するには?

次のファイルをtarとzipに圧縮します。

/opt/abc/xyz/abc.xml

到着する:

/tmp/backup/abc.xml.tar.gz

/opt/abc/xyz/(same path)解凍してディレクトリに抽出しようとしています。

私は次のコマンドを見つけました。ユーザーとして実行しましたが、rootエラーや出力が見つかりませんでした。以下のコマンドはabc.xmlそれを抽出し、abc.xml.tar.gz名前をabc.xml_v9

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

出力は

/opt/abc/xyz/abc.xml_v9

tar のマニュアルページには次の情報が表示されます。

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):

誰かがいくつかの例で上記のコマンドを理解するのに役立ちますか?

ベストアンサー1

サンプルファイルのソース/tmp/backup/abc.xml.tar.gzとターゲットを使用してください/opt/abc/xyz/abc.xml_v9。次のコマンドを使用できます。

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

あなたは得るでしょう

/opt/abc/xyz/abc.xml_v9

望むより:

https://stackoverflow.com/questions/21790843/how-to-rename-files-you-put-into-a-tar-archive-using-linux-tar

https://www.gnu.org/software/tar/manual/html_section/transform.html#transform

おすすめ記事