When try to install dropbox from command line, I read the commands
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
what does -
mean here? is it previous directory?
Some commands accept -
in place of a filename, either:
-
argument passed to wget
after -O
is doing.-
argument passed to tar
after xzf
.The command you showed downloads an archive file with wget
and unpacks it with tar
. To achieve this, the output of wget
is piped (|
) to the input of tar
. This is why wget
writes to standard output instead of a file and tar
reads from standard input instead of a file.
-
.. So if -
is an operand for a "file option" and it has a special meaning, then it must be that of stdin/stdout. The program is free to not treat as a special case and simply look for file -
-
)
-
specially at all, treating it as a literal filename. The only way to go against the guideline is to treat -
specially but with some other meaning than the ones the guideline suggests.
Jun 19, 2019 at 19:39
That's just a filename that a lot of Unix programs interpret as "instead of actually opening a file, read from stdin
(or write to stdout
)."
That means reading from the input that gets streamed into the program; in your case, that's the output of wget.
./-
if you actually want to open a file named -
.
Jun 18, 2019 at 20:05
stdin
is a file descriptor, and -
is the name you supply to use that. It's not a file name from the OS's perspective, though. Only from the user perspective.
Jun 19, 2019 at 6:15
/dev/stdin
is just a convenience file name offered by some kernel facility. There's usually no fopen("/dev/stdin", "r")
happening anywhere when you write a program that chooses to use stdin; you just go ahead and use the extern FILE* stdin
that your libc header provided you with; by the way, that is the integer file descriptor 0
.
Jun 19, 2019 at 6:46
The -
argument to tar
specifies that the archive should be read from stdin
instead of a file. From the GNU tar manual:
If you use
-
as an archive-name,tar
reads the archive from standard input (when listing or extracting files)
Other commands have the same behavior, and it is specified by the POSIX.1-2017 standard:
Guideline 13:
For utilities that use operands to represent files to be opened for either reading or writing, the '
-
' operand should be used to mean only standard input (or standard output when it is clear from context that an output file is being specified) or a file named-
.
f -
. This might make finding the answer in the man pages a little easier.wget
andtar
. That way, the respective developers can improve their documentation so that future users don't stumble over the same problems again. In other words: be a hero and make the world a better place!$TAPE
is set.