I\'m trying to create a tar archive with a couple files, but rename those files in the archive. Right now I have something like this:
tar -czvf file1 /some/p
With --transform
, there's no need to make a temporary testDir first. To prepend testDir/
to everything in the archive, match the beginning anchor ^:
tar --transform "s|file3|path/to/renamedFile3|" \
--transform "flags=r;s|^|testDir/|" \
-czvf my_archive.tgz file1 /some/path/to/file2 file3 etc
The r
flag is critical to keep the transform from breaking any symlink targets in the archive (which also match ^).