Detailed explanation of system input and output management in Linux

Detailed explanation of system input and output management in Linux

Management of input and output in the system

1. Understand the input and output of the system

In Linux system, 1 indicates correct output and 2 indicates incorrect output

2. Manage input and output symbols

(1) Output redirection (output to a specified location)

> ## Redirect correct output 2> ## Redirect error output &> ## Redirect all output

Note: The following experiments should be completed among ordinary users

find /etc/ -name passwd > file1 ##Direct correct output to file1 (wrong output that is not put into the file will be displayed)
find /etc/ -name passwd 2> file2 ##Direct error output to file2 (will display correct output that was not put into the file)
find /etc/ -name passwd &> file3 ##Direct all output to file3 

file ##Clear file (because the '>' symbol will overwrite the source file when it is output, so > file will overwrite the source file with a blank space to achieve the effect of clearing)


(2) Output append

>> ##Append correct output to the end of the file 2>> ##Append error output to the end of the file&>> ##Append all output to the end of the file

Note: Appending will not overwrite the original file contents

(3) Input redirection

<<EOF

content

EOF (EOF here can be any combination, but it needs to be the same before and after)

for example:

vim file
Enter passwd student<<EOF
heihei
heihei
EOF

Command line input file ##Modify student user password

3. Pipeline

Function: turns the output of the previous command into the input of the next command in the pipeline

Note: The pipeline only allows correct output to pass. If you want incorrect output, you should use 2>&1 to convert the incorrect output number into the correct output number before outputting it.

| ##Turn the correct output of the first command into the input of the second command after the pipeline 2>&1 ##Turn the error output numbered 2 into the correct output numbered 1 tee ##Copy the output to the specified location For example: ls /bin |wc -l ##Count how many files there are in /bin find /etc/ -name passwd 2>&1 | wc -l ##Turn the error output numbered 2 into the correct output numbered 1 and count the number find/etc/ -name passwd 2>&1 | tee file |wc -l ##Turn the error output numbered 2 into the correct output numbered 1 and put them into the file file and count the number 


Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Explanation of installation and configuration of building go environment under linux
  • Summary of Linux cut command usage
  • Detailed explanation of Linux system input and output management and common functions of vim
  • Linux shell - Example of how to test file system attributes by identification
  • Various judgments of if in linux shell
  • Linux shell pushd, popd and dirs usage explanation
  • How to print various color fonts and backgrounds in the Linux shell console
  • View the dependent libraries of so or executable programs under linux
  • Explanation of building graph database neo4j in Linux environment
  • Play with the connect function with timeout in Linux

<<:  Optimizing the performance of paging query for MySQL with tens of millions of data

>>:  Summary of twelve methods of Vue value transfer

Recommend

Native js to achieve puzzle effect

This article shares the specific code of native j...

Example of Html shielding right-click menu and left-click typing function

Disable right-click menu <body oncontextmenu=s...

How to submit the value of a disabled form field in a form Example code

If a form field in a form is set to disabled, the ...

Detailed explanation of how to synchronize data from MySQL to Elasticsearch

Table of contents 1. Synchronization Principle 2....

When to use table and when to use CSS (experience sharing)

The main text page of TW used to have a width of 8...

Vue implements verification code countdown button

This article example shares the specific code of ...

Detailed graphic explanation of mysql query control statements

mysql query control statements Field deduplicatio...

Detailed process of getting started with docker compose helloworld

Prerequisites Compose is a tool for orchestrating...

js implements the algorithm for specifying the order and amount of red envelopes

This article shares the specific code of js to im...

Detailed explanation of Mysql's concurrent parameter adjustment

Table of contents Query cache optimization Overvi...

Detailed explanation of Tomcat core components and application architecture

Table of contents What is a web container? The Na...

Detailed explanation of Nginx proxy_redirect usage

Today, I encountered a little problem when I was ...