I want to create a .tgz from the content of a directory. I also want to strip the leading "./
" from the tar'ed content.
I had done this as follows:
cd /path/to/files/ && find . -type f | cut -c 3- | xargs czf /path/to/tgz/myTgz.tgz
I learned recently that using xargs
may not be the best way to pull this off because xargs
may invoke tar
multiple times if the cmdline arg list gets too long, and I was advised to make use of tar
's ability to read a list of input files from stdin. I ended up finding this article on how to do this. However, I find that the recommendation...
cd /path/to/files/ && find . -type f | cut -c 3- | tar czf foo.tgz -T -
...seems to not be portable. It runs fine on my dev PC, but on a busybox target, I get the following error from running the same command:
tar: can't open '-': No such file or directory
So, my question: is there a truly portable/global way to invoke tar
to create a .tgz
by feeding it input files from stdin (as opposed to cmdline arguments)?
(It is not an option available to me to install alternatives to tar
such as gnutar
/bsdtar
/etc.)
(Secondary question: Why does the "-T -
" argument to tar
denote "read files from stdin
"? From the tar
man page, all I could find was that "-T
" means:
get names to extract or create from FILE
... but I couldn't see any reference to a plain "-
")
tar
is not a POSIX utility, a truly portable (as in "standard") implementation may not be found.pax
, on the other hand, is a POSIX utility. – Kusalananda Jan 03 '19 at 19:31pax
isn't available in Busybox (at least in the version of Busybox I have to work with). I think I may have to resign myself to using the sub-optimal approach usingxargs
. – StoneThrow Jan 03 '19 at 19:47pax
is portable in the sense of standard, but not portable in the sense of being part of the busybox suite. – Gilles 'SO- stop being evil' Jan 03 '19 at 20:27