Detailed explanation of Linux system input and output management and common functions of vim

Detailed explanation of Linux system input and output management and common functions of vim

####Management of input and output in the system####

1. Understand the system's input and output redirection

Input redirection refers to importing a file into a command, while output redirection refers to writing data information originally to be output to the screen into a specified file.

2. Manage input and output symbols

##Output redirection

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

Notice:

Redirection will overwrite the original file content

>> ##Will not overwrite the original file content
2>> ##Error output, no overwriting
&>> ##All output, no overwriting

####find command####

Used to search for files in a specified directory. Any string preceding the argument is interpreted as the name of a directory to search. If you do not set any parameters when using this command, the find command will search for subdirectories and files in the current directory. And all the found subdirectories and files will be displayed.

Common options:

-group<group name>: Search for files or directories that match the specified group name;

-name<template style>: specifies a string as a template style for searching files or directories;

-nouser: Find files or directories that do not belong to the local host user identification code;

-user<owner name>: Search for files or directories with the specified owner name;

Here is an example:

   

####Application of pipelines####

1. The role of pipelines

The function of the “|” pipe is to turn the output of the previous command into the input of the next command.

Notice:

The pipe only allows correct output to pass through

The output through the pipeline will become input, and these outputs that become input will be processed by the second command.

If you need to save the output, you need to copy the output. The command used is "tee"

This experiment is performed under ordinary users:

find /etc/ -name passwd | wc -l ##You will see the result 2, because the error output cannot be piped find /etc -name passwd 2>&1|wc -l ##You will see 19, because the output numbered 2 is converted to number 1 by "2>&1"
find /etc -name passwd 2>&1|tee file |wc -l ##Save a copy of the output to a file and then count the number of lines

Summary: The difference between 2>&1 and &>

&> is redirection output, so you need to specify where to redirect to

2>&1 No redirection, or find's output command is converted to input using the pipe character

   

####Input Redirection####

cat >file <<EOF
hello
WORLD
EOF

####Common functions of vim##

1. vim mode

Command Mode

Browse files, temporarily change the working mode of vim, and process characters in batches

Insert Mode

Edit the file contents

Exit Mode

Exit vim program

2. Command mode

1) Adjust the way vim works

In vim program

:set adjustment parameters

The parameters are as follows:

:set nu ##Display line number before each line

:set nonu ##Cancel line number display

:set mouse=a ##Show mouse

:set cursorline ##Show line

Notice:

The vim working mode set in the vim program is temporary and will be restored after vim is closed.

If you want to permanently save the working method of vim, you need to edit (add or delete) the vim configuration file: /etc/vimrc

2) Searching for characters

/Keyword

n matches downwards

N Upward Match

3) Character management

y

yl ##Copy a letter <C-F12>

y3l ##Copy 3 letters

yw ##Copy a word

y3w ##Copy 3 words

yy ##Copy 1 line

y3y ##Copy 3 lines

d

dl ##Delete a letter

d3l ##Delete 3 letters

dw ##delete 1 word

d3w ##delete 3 words

dd ##delete 1 line

d3d ##Delete 3 lines

c

cl ##Cut 1 letter

c3l ##Cut 3 letters

cw ##Cut 1 word

c3w ##Cut 3 words

cc ##cut 1 line

c3c ##Cut 3 lines***"Note***: After cutting, vim will enter insert mode. If you want to paste, press [esc] to exit insert mode and then press p to paste"

p ##Paste

u##Undo

ctrl+r ##Redo

4) vim visualization mode

ctrl + v ##In this mode, you can select area operations to add characters in batches

ctrl + v Select the column where you want to add the characters---> Press uppercase I---> Add the characters---> Press [esc]
5) Character replacement

:%s/character to be replaced/character to be replaced/g

:%s/:/@/g ##Replace the full text with @

:1,5s/:/@/g ##Replace lines 1-5 with @
Notice:

%s indicates all rows

g marks all columns

   

6) Split screen function of vim

ctrl+w s ##Split the screen up and down

ctrl+w v ##Split screen left and right

ctrl+w c ##Close the screen where the cursor is

ctrl+w up, down, left, and right ##Move the cursor to the specified screen

:sp file2 ##Edit the current file and file2 at the same time

7) Cursor movement in command mode

gg ##Move the cursor to the first line of the file

G ##Move the cursor to the end of the file

: Number ##Move the cursor to the specified line

#####Insert Mode######

1

) Cursor movement in insert mode

i ##Insert at the cursor position

I ##Insert at the beginning of the line where the cursor is

o ##Insert the next line under the cursor line

O ##Insert the line above the line where the cursor is located

a ##The next character of the cursor is inserted

A ##Insert at the end of the line where the cursor is

s ##Delete and insert the character where the cursor is

S ##Delete and insert the line where the cursor is

####vim's exit mode#####

:q ##Exit, used when the file content has not been changed

:wq ##Exit and save

:q! ##Force exit without saving, used when you do not want to save after changing the file

:wq! ##Force exit and save. Used when writing read-only files.

Notice:

The read-only file being edited must be the current user's file

Or the current operating user is root

Summarize

The above is what I introduced to you about Linux system input and output management and common functions of vim. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

You may also be interested in:
  • Play with the connect function with timeout in Linux
  • Detailed explanation of the solution to npm ls errors caused by fsevents module under Linux
  • Explanation of installation and configuration of building go environment under linux
  • Summary of Linux cut command usage
  • 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
  • Example explanation of alarm function in Linux

<<:  Eight implementation solutions for cross-domain js front-end

>>:  MySql common query command operation list

Recommend

Pure CSS to achieve cloudy weather icon effect

Effect The effect is as follows ​ Implementation ...

Solutions for high traffic websites

First: First, confirm whether the server hardware ...

Steps to solve the MySQL 8.0 time zone problem

Software Version Windows: Windows 10 MySQL: mysql...

A brief discussion on using virtual lists to optimize tables in el-table

Table of contents Preface Solution Specific imple...

Website User Experience Design (UE)

I just saw a post titled "Flow Theory and Des...

MySQL date processing function example analysis

This article mainly introduces the example analys...

HTML line spacing setting methods and problems

To set the line spacing of <p></p>, us...

How to configure Http, Https, WS, and WSS in Nginx

Written in front In today's Internet field, N...

A brief discussion on how to customize the host file in Docker

Table of contents 1. Command 2. docker-compose.ym...

JavaScript implements mouse control of free moving window

This article shares the specific code of JavaScri...

Let's talk about what JavaScript's URL object is

Table of contents Overview Hash Properties Host p...

Solution to the docker command exception "permission denied"

In Linux system, newly install docker and enter t...

MySQL deadlock routine: inconsistent batch insertion order under unique index

Preface The essence of deadlock is resource compe...

JavaScript article will show you how to play with web forms

1. Introduction Earlier we introduced the rapid d...