-1

Lately I ran into a command:

curl https://start.spring.io/starter.tgz -d dependencies=webflux,actuator | tar -xzvf -

curl itself does not download the tgz file, since it is not wget. tar -xzvf does not download any file either. But tar -xzvf - does "download" files. I didn't find any - explanation in tar manpage, and I don't think it relates to login shell. I guess it is the shell I used. What is this -?

SouravGhosh
  • 553
  • 5
  • 12
Tiina
  • 145
  • 8

2 Answers2

2

curl does download the file. As opposed to wget, it writes the downloaded file to stdout unless you specify -o option to save the file.
As to the - in tar command, it goes together with the -f option, and you can find the explanation in info tar, section 6.1 Choosing and Naming Archive Files :

If you use '-' as an ARCHIVE-NAME, 'tar' reads the archive from standard input (when listing or extracting files), or writes it to standard output (when creating an archive). If you use '-' as an ARCHIVE-NAME when modifying an archive, 'tar' reads the original archive from its standard input and writes the entire new archive to its standard output.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
SparedWhisle
  • 3,588
  • 4
  • 22
  • 35
  • The new thing to me is many commands like `cat | grep` would read stdin without being explicitly told so (like using parameter `-`), and at the same time these commands could be given a file to work on. While tar is special... – Tiina Dec 22 '19 at 10:25
  • Actually `tar` is _not_ special. You should read the `cat` manual. You are in for a surprise. A further surprise awaits at https://unix.stackexchange.com/a/41842/5132 . – JdeBP Dec 22 '19 at 11:32
1

Curl download the file and send it to STDOUT. Same can be done with wget.

Then pipe (|) send this file to STDIN of tar command. And this dash (-) tell tar to use STDIN for file instead of file from filesystem.

Romeo Ninov
  • 16,541
  • 5
  • 32
  • 44