You can modify filenames (among other things) with --transform
. For example, to create a tape archive /tmp/foo.tar
, putting files /etc/profile
and /etc/bash.bashrc
into it while also renaming profile
to foo
, you can do the following:
tar --transform='flags=r;s|bar|foo|' -cf file.tar file1 file2 bar fubar /dir/*
Results of the above is that bar
is added to file.tar
as foo
.
The r
flag means transformations are applied to regular files only. For more information see GNU tar documentation.
You can use --transform
multiple times, for example:
tar --transform='flags=r;s|foo|bar|' --transform='flags=r;s|baz|woz|' -cf file.tar /some/dir/where/foo/is /some/dir/where/baz/is /other/stuff/* /dir/too
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…