8
2
I have a directory setup like the following:
folder_x
file.y
file.z
I would like to create a tar file so that when it's extracted the structure will look something like this:
dir_q/folder_x
dir_q/file.y
dir_q/file.z
How could I get this to work by using tar
? For reference, the current command that I'm using is:
tar -czf archive.tar.gz file.y file.z folder_x
1Here's how I do it: tar -czf archive.tar.gz --transform 's,^,dir_q/,' file.y file.z folder_x
Sed allows , instead of /, avoiding ambiguity when there are forward slashes in your expression. Normally I would say you can escape the slash with a backslash, but sed (at least, gnu sed) doesn't interpret it correctly. – jdb – 2014-07-15T21:33:58.887
tar --transform doesn't seem to work on MacOS – Alexander Mills – 2018-05-15T19:36:42.363
In MacOS you could install macports and gnutar to get the --transform option. Or download & compile gnutar yourself. – Marnix A. van Ammers – 2018-05-16T23:06:03.083
Hmm, it doesn't seem to be doing it properly:
file.z
->dirfile.z
anddirfolder_x
. I'll play around with the regex too see if I can get it the way I want it. – None – 2011-01-25T19:40:20.423