Firstly, if you want to archive a directory, having the identical file structure in the archive is the best practice for taking that snapshot. What you are asking for is the renaming of your files to include its parent directories succeeded by colons followed by the filename. However strange to me this is out of context, I did manage to get pretty close using the
use sed replace EXPRESSION to transform file
An example of this is outlined in this stackexchange answer (Though be aware that it is not proper
sed syntax). Using
--transform your command would be this:
tar czvf documents.tar.gz --transform 's/\//:/g' documents
Unfortunately, this did not have the desired effect, as it keeps your subdirectories in the archive but they are empty, and the files are at the root of the archive, not in the first parent directory.
I thought I had a solution for you using
-C, --directory option, but it would not be very dynamic, nor would it accomodate for maintaining the directory names of files in the new file name.
The solution I did find is a hybrid of what you have and the use of the transform command:
find documents -type f -print0 | xargs -0 tar czvf test.tar.gz --no-recursion --transform 's/\//:/g' --transform 's:\::/:1' documents/
Also, in your question you name your file with the
.gz extension but it was lacking the
-z, --gzip option.
Hope this helps,