What I'm looking for is a way to pass in arbitrary data through STDIN, and have it get tar'd up as if its a normal file.
I tried this
$ echo test | tar -cf test.tar /dev/stdin
and that gives me a test.tar
file with the contents dev/stdin
. The stdin
file is a link to /proc/self/fd/0
.
What I want instead is for dev/stdin
inside the TAR file to be a regular file with the text test
inside. A similar thing happens with:
$ tar -cf test.tar <(echo test)
but the names are different.
Is this doable?
Best Answer
I don't think you can do what you want here. The problem with your approach is that
tar
deals in files and directory trees, which you're not providing it with commands such as this:Even when you attempt to "wrap" your strings in temporary files using subshells such as this:
You can see your content is still being TAR'ed up using these temporary file descriptors:
If you're intent is just to compress strings, you need to get them into a file context. So you'd need to do something like this:
You can see the file's present inside of the TAR file:
Replicating data using tar
Most that have been working with Unix for several years will likely have seen this pattern:
I used to use this all the time to replicate data from one location to another. You can use this over SSH as well. Other methods are discussed in this U&L Q&A titled: clone root directory tree using busybox.
Backing up /
There's also this method if you're intent is to back up the entier HDD:
References