What does "-" mean as an argument to a command?

I found this link on how to open tgz in one step.

gzip -dc target.tar.gz | tar xf -

What does the ‘-‘ mean?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

It’s a common convention to use - in a filename argument to mean stdin or stdout; tar follows the same convention. From the man page:

   -f, --file [HOSTNAME:]F
          use archive file or device F (default "-", meaning stdin/stdout)

Solution 2

Another convention is to use ‘-‘ to indicate the end of flags, and the beginning of file names. That behavior is built-in to the getopt(3) on RedHat 4, at least. I can’t find a Red Hat man page that uses ‘-‘ to indicate end-of-arguments, they all seem to use ‘–‘ to do that. The awk man page has ‘–‘ in that context, so maybe only old “heirloom” Unix or Solaris commands use ‘-‘ as a arguments – file names separator.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply