Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "-" mean in this linux command?

Tags:

linux

cat

I am learning the cat command of linux, and I found this command :

$ echo 'Text through stdin' | cat - file.txt

What does "-" mean here? If I don't type it , then 'Text through stdin' will not be shown.

like image 679
huashui Avatar asked Aug 22 '13 13:08

huashui


People also ask

What does `` mean in Linux?

One of the most useful features of shell scripts is the lowly back quote character, usually called the backtick (`) in the Linux world. Be careful—this is not the normal single quotation mark character you are used to using for strings.

What does '!' Mean in Linux?

In Bash, the exclamation mark (!) is used with the pound (#) symbol to specify the interpreter path. This usage is called “shebang” and is denoted as: #!interpreter [arguments] In shell scripts, we can use it to specify bash as an interpreter: $ cat welcome.sh #!/usr/bin/bash echo "Welcome !!!"

What does “./” mean in Linux?

command line - What does "./" mean in linux shell? - Ask Ubuntu Closed 8 years ago. What does the command ./ mean? For example, sometimes we call a file with ./config, sometimes ../config, thanks ./config means you're calling something in the current working directory. In this case config is an executable.

What do the characters in the Linux terminal mean?

However the characters do have a special meaning for some of the apps that you run inside the terminal - usually your shell: These are just some of the expansions the shell performs on command lines; there are quite a few. Note that these expansions happen before the command is executed; the command will never “know” that you typed e.g.

Does the Linux shell know when you type in a command?

These are just some of the expansions the shell performs on command lines; there are quite a few. Note that these expansions happen before the command is executed; the command will never “know” that you typed e.g. What is something the Linux Terminal cannot do?

What does “./” do in the Linux terminal?

And for that, either execute: What does "./" do in the Linux Terminal? At any time when you are using Linux from the command line you are located somewhere on the file system hierarchy. For non-root users this usually means somewhere in their home directory. ./ is shorthand for wherever you are located on the current directory.


2 Answers

it is common to write stdin as dash (-).

even man cat mentions that:

With no FILE, or when FILE is -, read standard input.

and the manpage even has an example illustrating the use of dash and ordinary filenames (which is quite close to your original question, but includes the answer):

   cat f - g
          Output f's contents, then standard input, then g's contents.
like image 144
umläute Avatar answered Oct 25 '22 16:10

umläute


- tells cat to read from stdin. This is quite common, a lot of apps read from stdin if you pass - to them.

Some apps use - as stdout.

Here is an example of downloading blender and instead of writing it to a file we write it directly to stdout and pipe it to tar, which expands it on the fly during download.

wget -c https://download.blender.org/source/blender-2.90.1.tar.xz -O - | tar -xzv

Here the -O - tells wget to write directly to stdout

like image 29
hashier Avatar answered Oct 25 '22 16:10

hashier