-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 -?

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.

2
  • 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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.