The easiest solution of course is to make a copy of your directory, then do your modifications, then do your tar
ing. And that's basically free in terms of disk space (aside from the changed blocks) and time effort if the file system you're doing this on is Btrfs, CIFS, NFS 4.2, OCFS2, overlayfs, or XFS, as these support reflink
s, i.e., copying a file doesn't actually copy the file's content. Only when the contents are changed, a copy of the original data extent is made. Use cp --reflink=always
.
As GNU tar
has no way to take input from anything but files, and if you specify a file, the path of that file will be significant, as it reflects the path in the archive, I'm afraid you'll not be able to do it any other way using tar
.
I was hoping that there is an in-memory solution.
The by far easiest way is picking a scripting language that is reasonable usable to you, and building your archive yourself instead of depending on the tar
program. For example, Python comes with the tarfile
module; it's easy to use, even for Python beginners. There's a lot of answers that contain that, some might be helpful to your solution. Haven't checked them, though.
tar
is not an option I guess, right? – pLumo Jan 12 '22 at 10:57