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

Steps for Vue to use Ref to get components across levels

Vue uses Ref to get component instances across le...

Solution to overflow:hidden failure in CSS

Cause of failure Today, when I was writing a caro...

Chrome 4.0 supports GreaseMonkey scripts

GreaseMokey (Chinese people call it Grease Monkey...

Summary of 10 must-see JavaScript interview questions (recommended)

1.This points to 1. Who calls whom? example: func...

A brief analysis of the best way to deal with forgotten MySQL 8 passwords

Preface Readers who are familiar with MySQL may f...

Implementing long shadow of text in less in CSS3

This article mainly introduces how to implement l...

Implementing simple tabs with js

Tab selection cards are used very frequently on r...

Share MySql8.0.19 installation pit record

The previous article introduced the installation ...

MySQL query optimization: causes and solutions for slow queries

Friends who are doing development, especially tho...

How to set a fixed IP address in CentOS7 virtual machine

Since my development environment is to install Ce...

This article will show you how to use SQL CASE WHEN in detail

Table of contents Simple CASEWHEN function: This ...