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

The ultimate solution for writing bash scripts with nodejs

Table of contents Preface zx library $`command` c...

js canvas realizes slider verification

This article example shares the specific code of ...

Usage of mysql timestamp

Preface: Timestamp fields are often used in MySQL...

How to implement Linux automatic shutdown when the battery is low

Preface The electricity in my residence has been ...

Pure HTML+CSS to achieve typing effect

This article mainly introduces the typing effect ...

How to implement CSS mask full screen center alignment

The specific code is as follows: <style> #t...

js to realize simple shopping cart function

This article example shares the specific code of ...

Sample code for implementing horizontal infinite scrolling with pure CSS3

The examples in this article are all written in s...

How to extract string elements from non-fixed positions in MySQL

Preface Note: The test database version is MySQL ...

How to migrate the data directory in mysql8.0.20

The default storage directory of mysql is /var/li...

MySQL Database Basics SQL Window Function Example Analysis Tutorial

Table of contents Introduction Introduction Aggre...

Let's talk in detail about the direction of slow SQL optimization in MySQL

Table of contents Preface SQL statement optimizat...

Implementation of MYSQL (telephone number, ID card) data desensitization

1. Data desensitization explanation In daily deve...