Redirect input, output, and pipe commands


提示:以下是本篇文章正文内容,下面案例可供参考

1. What is redirection?

  • "Redirection" is to re-change the direction of command input and output.
  • The original input direction of the command is the keyboard, so this input is called standard input.
  • The original output direction of the command is the display, so this output is called standard output.

2. Redirect command

1. Redirect output command

Command format:
a command with output results > file name

Function description:

  • Direct the output of this command to a file.
  • The command must have an output before it can be placed before ">".
    Demo:

insert image description here
insert image description here
insert image description here

2. Redirect input command

Command format:
a command that needs to input data from the keyboard < file name

Function description:

  • If the command needs to get one or some input data from the keyboard during execution, you can use "<" to redirect its standard input so that the input data it needs comes from a file instead of the keyboard.

Demo:

  • Use the mail command to send mail to other users in the Linux system.

insert image description here
insert image description here
insert image description here

Use the file to improve:

insert image description here
insert image description here

3. Other commands

  • "<" can be used or not

insert image description here

  • Mixed use of redirects

insert image description hereinstant tune

重定向混合使用需要注意的问题:

insert image description here

  • Usage of "-"

insert image description here

3. Pipeline commands

Command format:
Command 1 | Command 2 | Command 3·····

Function description:

  • Pass the output result of the previous command through the pipeline command "|" as the input data of the next command.
  • Both sides of the pipeline command can only be commands, not files.

Function Demo:
insert image description here
Notes:

insert image description here
insert image description here


Guess you like

Origin blog.csdn.net/ATTAIN__/article/details/124830943
Recommended