Linux lessons next day study notes

Source: Internet
Author: User
Tags rsyslog

5) Vim text mode edit file
vim [filename] # #进入到命令模式
Command mode cannot edit the file if you want to edit the file to enter insert mode
Press "I" to enter insert mode
If you finish editing, press "ESC" to exit Insert mode, enter ": Wq", Save exit

VIM [filename] If the file name does not exist, it will be created automatically
Vim does not have an action object opened directly, after editing the file to enter ": WQ [FileName]"

": q!" Indicates no save, forced exit
": wq!" Indicates force save and exit

####################
The following summarizes for yourself, not necessarily correct:
"I" means enter insert mode
"A" means to move one character to the right and into insert mode
"s" means to delete the current character and enter insert mode
"S" means to delete entire line characters and enter insert mode
"CC" means to delete entire line characters and enter insert mode
"C" means to delete from the cursor to the end of the line and into insert mode
"O" means inserting a row down and into insert mode
"X" means to delete one character to the left
"X" means to delete one character to the right and one character to the left if no character is followed
"D" means to delete from the cursor to the end of the line, and if there are no characters later, delete one character to the left
"DD" means to delete an entire row
"P" revokes the last Delete
"U" undo
"R" replacement
"J" turns the end of the line into a space.
"H" means moving to the left in character units
"L" means moving to the right in a character unit
"B" means moving to the left with a word, and the cursor resting on the first character of the next word
"B" means moving to the left with a word, and the cursor resting on the first character of the next word
"E" means moving to the right in a word, with the cursor resting on the last character of the next word
"W" means moving to the right in a word, with the cursor resting on the first character of the next word
"K" means jump to the same position as the previous line
"J" means jump to the next line in the same position
"GG" means jumping to the beginning of the first valid character
"H" means to jump to the first valid character of the start
"G" means jump to the end
"L" means jump to the beginning of the last line
"K" means man [current character]
"ZZ" Save exit
####################

6) CD Switch working directory
cd [Directory] # #切换工作目录到指定目录
CD-# #切换工作目录到之前所在目录
CD ~ # #切换到自己的家目录
CD ~usernmae # #切换到指定用户家目录
Cd.. # #进入到当前目录的上级目录

7) LS lists directory or file information
LS # #如果后面没有目标那么默认目标为当前目录
LS Direcory|filename # #列出文件或目录内容
ls-d Direcotry # #列出目录本身
Ls-l Filename|dorectory # #列出文件或目录里面内容的属性
Ls-ld Directory # #列出目录本身属性
Ls-a # #显示目录中的所有内容, including with "." Hidden files at the beginning
Ls-r # #第归显示目录中的内容

####################
For example:
[Email protected] desktop]# mkdir-p 111/222/
[email protected] desktop]# Touch 111/222/333
[email protected] desktop]# Touch 111/222/.444
[Email protected] desktop]# LS-A 111
.  .. 222 # # "." Represents the current directory, "..." Represents the top level of the current directory
[Email protected] desktop]# ls-a 111/222
.  .. 333.444
[Email protected] desktop]# Ls-ar 111
111:
.  .. 222

111/222:
.  .. 333.444

"LL" = "ls-l"

L. # #显示当前目录下所有隐藏文件
"L." = "ls-d. *"
For example:
[[Email protected] desktop]# CD 111/222
[Email protected] 222]# L.
.  .. .444
[Email protected] 222]# ls-d. *
.  .. .444
####################

8) CP File copy
CP is the process of creating a new file

CP file File1 file2. Directory # #把file file1 file2 copied into directory
CP File Test # #建立test文件模板为file
Cp-r Directory Direcotry1 # #复制目录

####################
[email protected] desktop]# Touch file1
[email protected] desktop]# Touch file2
[Email protected] desktop]# mkdir 111/
[Email protected] desktop]# mkdir 222/
[email protected] desktop]# cp file1 file2 111/# #将法文件file1和文件file2复制到目录111中
[[email protected] desktop]# vim file1 # #输入一串字符, save exit
[email protected] desktop]# cp file1 File2 # #将文件file1中的内容复制到文件file2
Cp:overwrite ' File2 '? Y # #是否覆盖? YES
[[email protected] desktop]# CP file1 test # #创建文件test and copy the contents of the file File1
[Email protected] desktop]# cp-r 111/222/# #将目录111整个复制进目录222中, ie 222/111/[file1,file2]
[[email protected] desktop]# cp-r 111/333/# #创建目录333 and copy the file in directory 111, i.e. 333/[file1,file2]
####################

9) MV Move or rename
The MV of the same disk is renamed, and the MV of different disks is the process of copying and deleting.

MV file File1 Direcotry # #移动file和file1到directory中
MV exists file does not exist file # #重命名文件
MV Westos/linux. # #把westos中的linux移动到当前目录. Represents the current directory

####################
[[email protected] desktop]# Touch 111
[[email protected] desktop]# Touch 222
[Email protected] desktop]# mkdir 123/
[Email protected] desktop]# MV 111 222 123/# #将文件111和文件222移至目录123中
[Email protected] desktop]# mv 123/111 123/222. # #将目录123中的文件111和文件222移至当前目录
[Email protected] desktop]# MV 111 333 # #将文件111重命名为文件333
####################

################### #4. Regular Expression ####################
* # #匹配0到任意字符
? # #匹配单个字符
[[: Alpha:]] # #匹配单个字母
[[: Lower:] # #匹配单个小写字母
[[: Upper:] # #匹配单个大写字母
[[:d Igit:] # #匹配单个数字
[[: Alnum:] # #匹配单个数字或字母
[[:p UNCT:] # #匹配单个符号
[: Space:] # #匹配单个空格

{} indicates a nonexistent or existing
{1..9} # #1-9
{A.. F} # #a-F
{1,3,5} # #135
{A,c,e} # #a C e
{1..3} {A.. C} # #1a 2a 3a 2a 2b 2c 3a 3b 3c

[] Indicates the existence of the
[A-c] # #a或者A或者b或者B或者c或者C
[A-c] # #a或者A或者b或者B或者c
[ABC] # #a或者b或者c
[1-3] # #1或者2或者3
[145] # #1或者4或者5
[^abc]| [!ABC] # #除了a并且除了b并且除了c

~ # #当前用户家目录
~username # #指定的用户家目录
~+ # #当前目录
~-# #当前目录之前所在目录

. # #当前目录
.. # #当前目录的上一级

####################
{} can both create and delete
[] can only be deleted

Touch fi "" Le # #表示创建了一个名为 "fi le" file
"CD ~-" is equivalent to "CD-"
####################

######################
###### Third Unit ######
######################

################### #1. man####################
Man->>manual # #man是手册的缩写
Man Mans # #查看man命令的帮助
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

Man 5 passwd # help #查看/etc/passwd file
Man 1 passwd # #查看passwd命令的帮助, 1 can be omitted

A shortcut to the man page
Down Key # #向上或向下一行
Pageup|pagedown # #向下一个屏幕或者向上一个屏幕
D|u # #向下或者向上半个屏幕
G|GG # #跳转页面到man最下面或最上面
/keyword # #搜索关键字, keywords are highlighted, n is matched, n up
Q # #退出帮助页面

####################
"passwd--help" = "/bin/passwd--help"

ll file # #查看文件的Modification time
[[email protected] desktop]# Touch file
[[email protected] desktop]# touch-a file
[[Email protected] desktop]# stat file
File: ' File '
size:0 blocks:0 IO block:4096 Regular empty file
device:fd00h/64768d inode:404876853 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Context:unconfined_u:object_r:admin_home_t:s0
access:2016-09-29 16:51:50.418866685 +0800
modify:2016-09-29 16:50:25.102868288 +0800
change:2016-09-29 16:51:50.418866685 +0800
Birth:-
[email protected] desktop]# ll file
-rw-r--r--. 1 root root 0 Sep 16:50 file

Requirement: Allow student user to force change password at next login
[[email protected] desktop]# Man 5 Shadow
Enter "/log" to find the desired content as follows:
Date of last password change # #文中第三个字段
......
The value 0 has a special meaning, which was that the user should
Change her pasword the next time she'll log in the system.
......
Press "Q" to exit
[Email protected] desktop]# Vim/etc/shadow
kiosk:[too long omit]:16261:0:99999:7::: # #找到第三个字段 "16261", modify it to "0"
Press "ESC" and enter ": wq!"
Re-login with student user, found that the verification was successful, was forced to change the password
####################

######################
###### Unit Fourth ######
######################

################### #1. Managing input and Output ####################
In a Linux system, the correct output number is 1, the error output number is 2

Use the normal user "student" in the system to execute the following command:
Find/etc-name passwd
Because the "student" user rights issue has 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

Find/etc-name passwd > File # #重定向正确输出
Find/etc-name passwd 2> File # #重定向错误输出
Find/etc-name passwd &> File # #重定向所有输出

Note: 2>,&> will overwrite the contents of the source file.
>file # #清空file

Find/etc-name passwd >> File # #追加正确输出
Find/etc-name passwd 2>> File # #追加错误输出
Find/etc-name passwd &>> File # #追加所有输出

Note: >&gt, 2>>, &>> will not overwrite the source file content, will characters the corresponding output word to the end of the file

The "|" pipe character, which is the function of the pipe to change the output of the pre-pipeline command into the input of the post-pipeline command

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

The wrong output in the system cannot be passed through the pipe character.
Use "2>&1" to change the wrong output number from 2 to 1

Tee copy output to specified location
Date|tee File|wc-l # #tee命令将date命令的输出复制到file中, and count the number of output lines

####################
The command entered first to Memory,memory and then to cpu,cpu to feedback the results to "/dev/pts/0", the output interface of the terminal.

"/dev/pts/0" is used by default to save the terminal output, "0" refers to the first terminal, "1" refers to the second terminal, and so on
Date >/dev/pts/0 # #将date命令的输出复制到 "/dev/pts/0", the output of the first terminal will be displayed on the output screen

[Email protected] desktop]# >file # #清空file. If file does not exist, file is created and content is empty
[[email protected] desktop]# WC file # #统计file容量信息, nothing
0 0 0 File
[Email protected] desktop]# echo >file # #输出一个空格到file
[[email protected] desktop]# WC file # #统计file容量信息, 1 lines 0 words 1 bytes
1 0 1 file
[[email protected] desktop]# echo 123 >file # #输出 "123" to File
[[email protected] desktop]# WC file # #统计file容量信息, 1 lines 1 words 4 bytes
1 1 4 file
[[email protected] desktop]# cat file
123
Note: Echo is equivalent to the C language in printf
printf () is a function that produces formatted output in the C language, and is typically used to output information to a standard output device in a prescribed format.

"Cat-n" number of rows for all outputs starting from 1
"Cat-b" and "Cat-n" are similar, except that blank lines are not numbered

[Email protected] ~]$ find/etc/-name passwd | Cat-b
Find: '/etc/pki/ca/private ': Permission denied
Find: '/etc/pki/rsyslog ': Permission denied
Find: '/etc/dhcp ': Permission denied
Find: '/etc/lvm/archive ': Permission denied
Find: '/etc/lvm/backup ': Permission denied
Find: '/etc/lvm/cache ': Permission denied
Find: '/etc/selinux/targeted/modules/active ': Permission denied
Find: '/etc/audit ': Permission denied
1/ETC/PASSWD # #发现仅对正确的输出进行了编号
Find: '/ETC/POLKIT-1/RULES.D ': Permission denied
Find: '/etc/polkit-1/localauthority ': Permission denied
2/etc/pam.d/passwd
Find: '/etc/firewalld ': Permission denied
Find: '/ETC/GRUB.D ': Permission denied
Find: '/etc/ipsec.d ': Permission denied
Find: '/etc/audisp ': Permission denied
Find: '/etc/vmware-tools/guestproxydata/trusted ': Permission denied
Find: '/etc/libvirt ': Permission denied
Find: '/etc/cups/ssl ': Permission denied
Find: '/ETC/SUDOERS.D ': Permission denied
[Email protected] ~]$ find/etc/-name passwd 2>&1 | Cat-b
1 find: '/etc/pki/ca/private ': Permission denied
2 find: '/etc/pki/rsyslog ': Permission denied
3 find: '/etc/dhcp ': Permission denied
4 find: '/etc/lvm/archive ': Permission denied
5 find: '/etc/lvm/backup ': Permission denied
6 find: '/etc/lvm/cache ': Permission denied
7 find: '/etc/selinux/targeted/modules/active ': Permission denied
8/etc/passwd
9 find: '/etc/audit ': Permission denied
10/etc/pam.d/passwd
Find: '/ETC/POLKIT-1/RULES.D ': Permission denied
Find: '/etc/polkit-1/localauthority ': Permission denied
Find: '/etc/firewalld ': Permission denied
Find: '/ETC/GRUB.D ': Permission denied
Find: '/etc/ipsec.d ': Permission denied
Find: '/etc/audisp ': Permission denied
Find: '/etc/vmware-tools/guestproxydata/trusted ': Permission denied
Find: '/etc/libvirt ': Permission denied
Find: '/etc/cups/ssl ': Permission denied
Find: '/ETC/SUDOERS.D ': Permission denied # #对所有输出都进行了编号

Note: "2>&1" is only available in the "|" , it only works when
For example:
[Email protected] ~]$ find/etc/-name passwd 2>&1 >file
Find: '/etc/pki/ca/private ': Permission denied
Find: '/etc/pki/rsyslog ': Permission denied
Find: '/etc/dhcp ': Permission denied
Find: '/etc/lvm/archive ': Permission denied
Find: '/etc/lvm/backup ': Permission denied
Find: '/etc/lvm/cache ': Permission denied
Find: '/etc/selinux/targeted/modules/active ': Permission denied
Find: '/etc/audit ': Permission denied
Find: '/ETC/POLKIT-1/RULES.D ': Permission denied
Find: '/etc/polkit-1/localauthority ': Permission denied
Find: '/etc/firewalld ': Permission denied
Find: '/ETC/GRUB.D ': Permission denied
Find: '/etc/ipsec.d ': Permission denied
Find: '/etc/audisp ': Permission denied
Find: '/etc/vmware-tools/guestproxydata/trusted ': Permission denied
Find: '/etc/libvirt ': Permission denied
Find: '/etc/cups/ssl ': Permission denied
Find: '/ETC/SUDOERS.D ': Permission denied
[[email protected] ~]$ cat file
/etc/passwd
/ETC/PAM.D/PASSWD # #发现只有正确的输出重定向到了file, i.e. "2>&1" does not take effect

[[Email protected] desktop]# Date | Tee File # #将date命令的输出复制到file中 and displayed in the output interface
Fri Sep 14:47:49 CST 2016
[[email protected] desktop]# cat file
Fri Sep 14:47:49 CST 2016
[[Email protected] desktop]# Date | Tee File | Wc-l
1
[[email protected] desktop]# cat file
Fri Sep 14:48:18 CST 2016
[[Email protected] desktop]# Date | tee/dev/pts/0 | Wc-l
Fri Sep 14:54:07 CST 2016
1
####################


This article from the "Schue Linux Learning Notes" blog, declined reprint!

Linux lessons next day study notes

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.