We know that the order of options of a Linux command doesn’t usually matter.įor example, the following two ls commands are identical, even though the options are in a different order: ls -F -a -l -color These commands ignore the Stdin.įor instance, when we execute the command “ rm file“, rm accepts the command-line argument file, which is indicating a file. Typical examples are those commands doing file handling, for example, cp, mv, and rm. However, not all Linux commands support reading from Stdin. We can see this kind of “command chain” pretty often in the real world. We can pipe the Stdout to further commands that support reading from Stdin, for example: $ ls -1 / | grep '^m' | sed 's/^m/OK_m/'
This command works because the grep command accepts reading from the Stdin. Simply put, here, the pipe converts the standard output (Stdout) of ls to standard input (Stdin) of the grep command. In the simple example above, we pipe the ls command’s result to grep and find out the root directories whose names begin with “m”. First of all, let’s see an example: $ ls -1 / | grep '^m' We need to understand what the pipe does before we answer this question.