Linux foundation

Help command:
1.man [parameter] command, open help manual
1. Command: Man 1 CD, CD, CP, MV, Printf
2. System call: man 2 system function, fork() process
3. C language library function: man 3 C language function, printf()

printf fork
Find it from the smallest number Just return to the help manual, if you can’t find the next one

2.help:
Internal: help command name
External: command name –help

type command

cd is a shell builtin internal

ls is aliased to `ls –color=auto’ external

3. View command related文件的路径:whereis [-mb] 命令

帮助-m,原代码文件-b

4. info 命令显示的是命令手册

One. vi / vim
vi [path/file name]

1. Command mode
2. Input mode
3. Last line mode

Command mode-i /o/a/ I/A/O–> Input mode
<----ESC key------

Command mode–: /? Command —> Last line mode

i: before the current cursor
a: after the current cursor
o: the next line of the line where the current cursor is located
I: The beginning of the line where the current cursor is located
A: The end of the line where the current cursor is located
O: The previous line of the line where the current cursor is located

p>

4 Basic usage
1) Commands in command mode: x: delete the character where the cursor is (cutting can be realized),
dd: delete the current line, (cutting can be realized)
dw:删除单词(当前光标到空格或回车)(可实现剪切)
yy:复制当前行到剪贴板
p:粘贴

ZZ:保存并退出

Move the cursor (down, up, left, and right keys, HJKL)

2) Commands in input mode:
Move the cursor (down, up, left, and right keys)

p>

3) Commands in unrun mode:
😡 save and exit
:w [file name] save
:q exit
:wq [file name] save and exit
:w! [File name] Force save
:q! Force exit
:wq! [File name] Force save and exit

:set nu Display line number
:set nonu不显示行号

到文档中查找字符是否存在
?查找字符
/查找字符n , shift+n(N)

替换:< /p>

: Starting line number, ending line number s/character to be replaced/new character/parameter

Default parameter: silently case sensitive, only replace The first of each line of

i: case-insensitive
c: prompt information (only change the first of each line)

e: case-sensitive
g: No prompt message (replace all)

Ending line number:
Line number:, to the end of the file $, %

5.vim to open multiple files
1. vi file name 1 file name 2 file 3. . .
:n skip to the next file
:N skip to the previous file
:e file name skip to the specified file, if the file name does not exist, create a new file
Note: only view at the same time To a file
:qExit all files

2.vi file name
:sp file name to open the file vertically: new file name
:vsp file name to open the file horizontally: vnew File name

ctl+ww switch window

:sp/vsp no file name opens the file where the cursor is currently

:new/vnew no file name creation When saving a new file, you need to add the file name, :wq file name

Note: You can see multiple files at the same time

Two. View file (normal file)

cat [parameter] [file name]
When you don’t write the file name, press the input on the keyboard and press Enter and display it on the display ====>Standard input Output command

-n: display the line number together on the screen
-b: display the line number together on the screen, but blank lines are not counted.
-t: Display on the screen together with special characters.

more [参数] 文件名
+n:从笫n行开始显示
-n: 定义屏幕大小为n行下翻命令:回车(单行下翻)
ctrl+f (turn down the whole page)
Space key (turn down the whole page)
If you do not exit to the end, press the q key.

less [parameter] file name
-N display the line number of each line
press q to exit
less command; space key to scroll one page;
enter key to scroll One line.

head [参数] 文件名
-n:指定显示多少行
head -5
head -n

tail [参数] 文件名
-n: specify how many lines to display

vi / vim view and edit

grep [parameter] the file to be searched for Path
-v Reversely filter out those that do not contain filter keywords
-i Ignore the case of keywords
-n Before displaying the column that matches the template style, mark the row number of the column
-r Find in the directory file

find -name file name

Linux check log common command: file

View logs: cat, more less,head ,tail,vim

1. Common commands for viewing logs
tail:

tail- 100f test.log Real-time monitoring of 100 lines of logs

tail -n 10 test.log
tail -10 test.log
tail -n -10 test.log

Display the last 10 lines of the log at the end of the log;

tail -n +10 test.log displays all the logs after the 10th line;

head:

Follow Tail is the opposite, tail is the number of log lines after viewing; examples are as follows:

head -n 10 test.log
head -10 test.log
head -n +10 test.log
Display the first 10 lines of log in the log file;

head -n -10 test.log Display all logs except the last 10 lines of the log file;

cat:

tac is to view in reverse order, the word cat is reversed; examples are as follows:

cat -n test.log | grep “debug” query the log of keywords

2. Application scenario 1: View by line number—filter out logs near keywords

1) cat -n test.log |grep “debug” Get the line number of the key log

2) cat -n test.l og |tail -n +92|head -n 20 Select the middle row of the keyword. Then check the log of the first 10 and last 10 rows of this keyword:

tail -n +92 means query 92 The log after the line

head -n 20 means to check the first 20 records in the previous query results

3. Application scenario 2: According to Date query log

sed -n’/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p’ test.log

Special note: The above two dates must be the log printed in the log, otherwise it is invalid;

First grep ‘2014-12-17 16:17:20’ test.log to determine whether the log is At this point in time

4. Application scenario 3: The content of the log is very large, and it is not convenient to print it on the screen.
(1) Use the more and less commands,

p>

Such as: cat -n test.log |grep “debug” | more This will be paged and printed, turn the page by clicking the space bar

(2) Use >xxx.txt to save it In the file, you can pull down the file for analysis when you arrive

For example: cat -n test.log |grep “debug” >debug.txt

three.压缩打包命令(压缩文件的后缀名: .tar.gz .bz2 .zip,.rpm..)(打包文件的后缀名:.tar)

一)归档、压缩
1.tar -cf file name.tar file name list to be archived

2.tar -czvf file name.tar.gz file name list to be archived

3.tar -cjvf file name.bz2 file name list to be archived

4.zip -r file name.zip file name list to be archived

Two) Unzip and file
1.tar -xf file name.tar -C path

2.tar -xzf file name.tar.gz -C path

3.tar -xjf file name.bz2 -C path

4.unzip file name.zip -d path

three) view, unarchive and compress
1.tar -tf archive file name.tar

2.tar -tzf archive and compress file name. tar.gz

3.tar -tjf archive and compress file Name.bz2

4.unzip -v Archive and compress the file name.zip

Four. User management (root)
1. Add user
useradd [parameter] username

-m: create user and create user’s home directory (omitted)
-M: create用户,不创建用户的主目录(手动创建mkdir 用户名文件夹, 需要将配置文件复制到用户名文件夹)

创建用户同时创建了组

2.设置用户Password: su root
passwd [username], modify the password of ordinary users

passwd, modify the password of the administrator user

3.su-username

4.userdel [Parameter] Username
Note: Usernames that are not used can be deleted.

-r: Delete the user’s home directory [ The password is available)

6. Create a group
groupadd group name

7. Add the user main group to the group
usermod- g Group name exists as user: user, group exists, change the group the user belongs to

useradd -g group name-m user does not exist: user does not exist, group exists, create用户时直接添加组(如不指定组,用户名就是组名)

-m可以省略

 

 

 

8. Delete group
groupdel group name

Note: Only groups that are not used can be deleted

< /p>

9、用户的系统文件
1).用户账号文件:/etc/passwd

` 2).影子密码文件:/etc/shadow

3). Group account file /etc/group

4). Group shadow password file /etc/gshadow

10. View users Group syntax: (ordinary user or administrator)
groups [user name]; display the group the user name belongs to

id [user name]; current user information

< p> User id, group id, group id

< p> 11. User group member change syntax:
gpasswd [-option] username and group name

-a Add users to the group -d Use to remove from the group
gpasswd- a a1 B ;

gpasswd -d a1 B;

注:不能移除主组用户名与组名必需是存在的

Leave a Comment

Your email address will not be published.