0

I get the following error when trying to uncompress piped tar file with the following command :

$ git archive --format=tar 0af62b1 | tar -xf -C /the/path/here/
tar: -C: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

The first part git archive --format=tar 0af62b1 outputs a tar file, printed on the screen. This output can be captured in a file by using the parameter --output file_name.

In the second part I'm trying to extract the content of the file into the indicated path. When run separately both work perfectly git archive 0af62b1 --output file_name followed by tar -xf file_name -C /the/path/here/.

Why piping is not possible in this case and how do I know if a certain command accepts piped input?

2
  • f requires a filename Nov 1, 2021 at 18:38
  • 1
    Your tar command interprets -C as the filename.
    – annahri
    Nov 1, 2021 at 20:39

2 Answers 2

2

I would try to pipe your git into tar -xf - -C /the/path/here/ where - is synonymous of the standard input. Or simpler tar -xC /the/path/here (- is the default file).

1
  • 1
    What the default file is depends on the tar implementation and version. With several implementations, it's still some tape device as tar is the tape archiver. With GNU tar, it's determined at compile time (defaults to -), but can also be overriden with the $TAPE env var. I'd recommend to always using -f - to specify stdin. Nov 1, 2021 at 19:17
1

The Problem is given in your error output:

$ git archive --format=tar 0af62b1 | tar -xf -C /the/path/here/
tar: -C: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

You are telling tar to use a file named -C which does not exist and hence you get failure.

In working case, you are giving a file named file_name which exists and every thing works.

Possible fix : remove "-f -C" in the command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .