Basic Linux Learning (iii)

Source: Internet
Author: User

In learning the Linux command, we will find that each command has a lot of parameters, if you want to have all the parameters are firmly remembered, it may be a little imposition, so we need to learn man. As the saying goes, to give people to fish as well as to teach people to fishing, learned man is equivalent to learn how to fish

1.man

Man's full name is actually manual the word, is the abbreviation of the Handbook. So this command is used to refer to the commands, files, interfaces, libraries, etc. that are unfamiliar to them.

How to use:

Man passwd # #查看passwd命令的帮助


The level of man

1 system commands

2 System interface

3 Function libraries

4 special files, such as device files

5 files

6 games

7 Package for the system

8 System Administration Commands

9 cores

How to use:

Man 5 passwd # #查看 help with the/etc/passwd file (we can experiment with it ourselves and see what the difference is with man passwd)

A shortcut to the man page

Down Key # #向上或向下一行

pgup| PGDN # #向上一个屏幕或向下一个屏幕

D|u # #向下或者向上半个屏幕

G|GG # #跳转到最下面或最上面

/keyword # #搜索关键字, keywords are highlighted, n is matched, n up matches

Q # #退出帮助页面


If we are developers, we will not let users see all the results of the operation, the user can see is only a friendly user interface. So, we're going to learn the management of input and output

2. Managing input and output

Performed in the system with a normal user


Find/etc-name passwd


Because the student user rights issue will have the following output

Find: '/etc/pki/ca/private ': Permission denied # #没有进入权力, error

Find: '/etc/pki/rsyslog ': Permission denied

Find: '/etc/audit ': Permission denied

/ETC/PASSWD # #正确输出

Find: '/ETC/POLKIT-1/RULES.D ': Permission denied

Find: '/etc/polkit-1/localauthority ': Permission denied

Find: '/etc/dhcp ': Permission denied

Find: '/etc/selinux/targeted/modules/active ': Permission denied

Find: '/etc/lvm/archive ': Permission denied

Find: '/etc/lvm/backup ': Permission denied

Find: '/etc/lvm/cache ': Permission denied

Find: '/ETC/GRUB.D ': Permission denied

/ETC/PAM.D/PASSWD # #正确输出

Find: '/etc/audisp ': Permission denied

Find: '/etc/firewalld ': Permission denied

Find: '/etc/cups/ssl ': Permission denied

Find: '/etc/ipsec.d ': Permission denied

Find: '/etc/libvirt ': Permission denied

Find: '/ETC/SUDOERS.D ': Permission denied

Find: '/etc/named ': Permission denied


If we just want to let the user see the correct output, shielding out the error output, then we need to let the error output in other places to display, whether it is the garbage box or the file files of their own definition, anyway, do not let it show, so we need to redirect it.

Find/etc-name passwd > File # #重定向正确的输出

Find/etc-name passwd 2> File # #重定向错误的输出

Find/etc-name passwd &> File # #重定向所有的输出


Note that:>,2>,&> overwrites the contents of the original file, so if we want to empty a file, we can also use the following command

>file # #清空file

But sometimes we do not want to overwrite the source file, we want it to be appended to the source file, of course, can also

Find/etc-name passwd >> File # #追加正确输出

Find/etc-name passwd 2>> File # #追加错误输出

Find/etc-name passwd &>> File # #追加所有输出

This way, using >> will not overwrite the original file content!


| The function of a pipeline is to input the output of the previous command as a command after the pipeline.


Ls/bin | Wc-l # #统计ls The number of lines that the/bin command outputs

But the wrong output cannot be piped, that is, the output identified as 2 in the system cannot be piped, and if you want to get him through the pipe, we're going to turn its identity into 1.

Use 2>&1 to change the wrong output number from 2 to 1


Tee copy output to the specified location (note that the copy is equivalent to cut)

Date |tee file |wc-l # #tee命令复制date命令的输出到file中, and counts the number of output rows



In the previous chapter, we have learned a little bit about vim editing files, and now let's get a more specific look at this powerful editor

3.vim


Vim can be configured in the VIM command mode (the so-called command mode is the one that cannot be edited when you open vim)

: Set Nu # #添加行号

: Set Nonu # #取消行号

: Set Mouse=a # #添加鼠标选择 (by default, the mouse is not available in vim)

: Set Cursorline # #显示行线

* The above settings are temporary

Permanent setting Mode:

VIM/ETC/VIMRC # #此文件是vim的配置文件, add the above parameter at the end of this file


Vim Command mode keyword search:

/keywords

N Match down

N Up match


Character Management in vim command mode

1. Copying of characters

YL # #复制一个字母

Y3L # #复制三个字母

YW # #复制一个单词

Y3W # #复制三个单词

YY # #复制一行

Y3Y # #复制三行

P # #复制完成后按 "P" paste (do not exit command mode)


2. Deletion of characters

DL # #删除一个字母

D3L # #删除3个字母

DW # #删除一个单词

D3W # #删除3个单词

DD # #删除一行

D3D # #删除3行


3. Cutting of characters

CL # #剪切一个字母

C3L # #剪切3个字母

CW # #剪切一个单词

C3W # #剪切3个单词

CC # #剪切一行

C3C # #剪切3行

ESC----->P # #剪切后会进入插入模式, be sure to exit Insert mode when pasting, paste in command mode


The visual mode of VIM

Press CTRL + V in command mode to enter visualization mode

In visual mode, you can select the characters in the area


Bulk add characters in Visual mode:

Ctrl + V Select the column in which you want to add characters

Press I to enter insert mode, enter the character to be inserted (note that this is capital I)

Press ESC to insert an entire column


Bulk modification of characters in command mode

:%s/the original character/replaced character # #只替换每一行中出现的第一个原有字符

:%s/the original character/replaced character/g # #替换所有

:%s/\t//g # #把全文的tab键替去掉, \ t = Tab key

:%s/^\ *//g # #把全文行首的空格去掉, "^\ *" indicates the space at the beginning of the line

:%s/^\#\ */#/g # #把全文 # After the space is removed


Vim's split-screen function

Ctrl+w S # #上下分屏

Ctrl+w V # #左右分屏

Ctrl+w C # #关闭光标所在屏幕

Ctrl+w up or down # #光标移动到指定屏幕



Fast movement of VIM cursors


In command mode:

: Number # #移动到指定的行

G # #文件最后一行

GG # #文件第一行


I # #光标所在位置进入插入模式

I # #光标所在行行首进入插入模式

A # #光标所在字符的下一个字符进入插入模式

A # #光标所在行行尾进入插入模式

O # #光标所在行下一行进入插入模式

O # #光标所在行上一行进入插入模式

S # #删除光标所在字符并进入插入模式

S # #删除光标所在行并进入插入模式


Vim's exit

: Q # #当用vim打开文件但没有对字符作任何操作时可直接退出

: q! # #当用vim打开文件并对字符作操作, quit all operations

: Wq # #保存退出

: wq! # #强行保存退出, effective for Superuser and file owner


VIM Handbook

Vimtutor # #vim的手册

: Q # #退出vimtutor


Gedit related shortcut keys

CTRL + N # #在gedit中打开一个新的tab

Ctrl+s # #保存文件

Ctrl+o # #打开文件

Ctrl+x # #剪切字符

Ctrl + V # #粘贴字符

CTRL + C # #复制字符

Yelp Help:gedit # #gedit的图形手册



Basic Linux Learning (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.