Julian A Avar C
Julian A Avar C

Reputation: 878

How would I tar extract pipe cd?

So I found out that I could pipe the following two commands:

sudo wget https://example.com/folder.tar.gz
sudo tar xzvf folder.tar.gz

like this:

sudo wget -q http://example.com/folder.tar.gz -O - | tar xzvf -

So now I was wondering how I could also cd into this folder.

I guessed:

sudo wget -q http://example.com/folder.tar.gz -O - | tar xzvf - | cd
# and
sudo wget -q http://example.com/folder.tar.gz -O - | tar xzvf - | cd -

but these two are not working. I'm very sure that I'm not understanding pipes very well.

Upvotes: 0

Views: 444

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

Pipes link up the output of one program to the input of another - just how a pipe sends the output from your garden tap (faucet) to your lawn sprinkler.

A minus sign (-) is a shortcut meaning either input or output - which one it means depends on position/context.

Your wget command grabs some data from the web and, because of the -, sends it through a pipe to tar.

The tar command reads that data from the pipe, because of its -, and creates some files and directories.

The tar command doesn't send anything down any further pipes, so there'd be nothing for cd to read. You also don't know the name of the directory you want to go to. If you did, you could go there as a follow-up action like this:

wget ... - | tar ... - ; cd SOMEWHERE

Or you could make it conditional on the tar command running successfully with:

wget ... - | tar ... - && cd SOMEWHERE

Upvotes: 1

Related Questions