How can I make tar read input from stdin?
Using -O
with c
is ignored, since no files are extracted. You'll get the same result either way:
$ tar c -O foo | tar t
foo
$ tar c foo | tar t
foo
Which is why I find your error surprising, since tar
is no coward if you specify a path.
tar
cannot read in file data from stdin for creating an archive, since then tar
will have no way of knowing what a file is - where one begins or ends, what its path and metadata is.
Related videos on Youtube
kos
Full-time Linux user. Currently dual-booting Parabola and Ubuntu. I've read and signed the Ubuntu Code of Conduct. My Launchpad profile
Updated on September 18, 2022Comments
-
kos over 1 year
I need to use
tar
in a pipeline inside a shell script to archive and compress some files.After having read the manpage for
tar
I was able to maketar
output tostdout
by running it along with the-O
argument, but I wasn't able to find out how to make it input fromstdin
. Since many commands read fromstdin
if no other input it's specified, I tried:pv ~/foo | tar c -O ~/foo.tar
but that didn't work:
tar: Cowardly refusing to create an empty archive Try 'tar --help' or 'tar --usage' for more information.
How can I make
tar
read input fromstdin
?-
TobyLL about 9 yearsPossible duplicate of stackoverflow.com/questions/2597875/…
-
zhongfu about 9 yearsIf you want to display progress, you might want to do the reverse:
tar c ~/foo | pv > foo.tar
-
kos about 9 years@zhongfu Thanks, but
pv
was there because I wanted to see the progress while pipingdd
output intar
, as you can deduce from my later follow-up question -
zhongfu about 9 yearsI didn't really get the point of archiving a disk image instead of storing it as is as it's quite pointless, but what I wanted to say was basically covered by @DavidFoerster's answer at that question, so yeah
-
kos about 9 years@zhongfu I agree with you that in most cases that's plain unuseful, but in that case I wanted to backup also single folders in the same backup file
-