This section will cover all kinds of commonly used linux Commands and some advanced management features of the system , In especial shell script The creation of , This part will be very useful in system automation operation and maintenance .

Linux Series articles

Quick start series --Linux--01 Basic concepts

Quick start series --Linux--02 File system management

Quick start series --Linux--03 System management

Quick start series --Linux--04 Expanding knowledge

When entering bash Before the introduction , First of all, we need to introduce vim Editor , Although today's editors are very powerful , such as sublime etc. , But some situations still need simple use vim To edit files , Because this part of the content is no longer the focus , Therefore, through a simple table to introduce its most basic commands .

command

Example

edit w Text

vi test.txt, Enter command mode by default

Edit mode

adopt i Characters enter

Command mode

adopt [Esc] Get into , adopt :wq Finish editing and save , among w To save ,q Exit ,:q! Means to force exit without saving

Common shortcut keys

dd Delete the line ,yy Copy the line ,[ctrl]+r Redo last action

u Recover from the previous exercise ,p Paste

Let's start bash Introduction to common commands , More content , It takes a little patience . This part recommends bash Script Learning as a new language , This strength will enable you to grasp well bash.

command

Example

type name

View command information

The display of variables 、 Set and cancel

echo $PATH, name=xionger, unset name

environment variable

HOME: User master file ,SHELL: The default is /bin/bash

HISTSIZE: The number of temporary orders ,PATH: Execute file lookup path , use : Separate

locale

View the system language environment information , Can pass /etc/sysconfig/i18n

Read user input from the keyboard

read [-pt] variable

read -p 'please keyin your name: ' -t 30 named

Declare variables declare

The default definition is string

declare –a, Define variables as arrays

declare –i, Define variables as integers

declare –x, Usage and export equally , Set the following variable as the environment variable

declare –r, Set to readonly

alias,unalias

Set... For the long command / Remove alias

history

View used commands ,history | grep named

Related configuration files

~/.bash_profile, /.bash_login, /.profile

Can pass source The configuration file , Read in the environment configuration

Stream redirection

ll / > ~/temp/llShow.txt, One > Representation ,2 A means append The way

Judgment basis of command execution

; && ||

Pipe Pipeline command

Subsequent commands depend on the result of the previous command ,ls –al /etc | less

Common string commands

cut –c Split characters ; grep character string , Find the line that contains this string

sort Sort order ; uniq To repeat the order ;wc Get the number of lines

Other commands :tr,col,join,paste,expand,split

Tip: If the order is too long , have access to \[Enter] Way to wrap .

The regular expression is in Linux Application : We are very familiar with the concept and use of regularization , There is no introduction here , Please refer to the blog -- Regular expressions . This paper mainly introduces its use in the system , There is only one purpose , To provide the basis for the operation and maintenance script . It's usually used in grep command in , such as grep –n 'the' demo.txt, here the You can use any regular pattern Replace . Besides , Can pass sed、awk Tools help query scripts , If necessary, you can query the relevant documents .

 #!/bin/bash
 # program: The user enters a file name , The system checks its directory and permissions 
 # History:
 PATH=/bin:/sbin:/user/bin:/user/sbin:~/bin
 export PATH

 #. Input file name 
 echo -e "please input a filename, it will check the filename's type and \
 permission \n\n"
 read -p "input filename : " filename
 test -z $filename &&
 #. Judge whether the file exists 
 test ! -e $filename &&
 #. Determine file type 
 test -f $filename && filetype='regular file'
 test -d $filename && filetype='directory'
 test -r $filename && perm='readable'
 test -w $filename && perm='$perm writable'
 test -x $filename && perm='$perm executable'
 #. Output information 
 echo "The filename: $filename is a $filetype"
 echo "And the permissions are : $perm"

Common logical structures

Logical structure

Example

Judging structure

if ["$yn"=="y"] || ["$yn"=="Y"]; then

echo "OK,continue"

elif ["$yn"=="n"] || ["$yn"=="N"]; then

echo "Fail"

else

echo "Default"

fi

Loop structure

for username in $users

do

id $username

finger $username

done

function

function printit(){}

stay Linux in , User Account information Is stored in a /etc/passwd In file , The common account management commands are as follows .

command

Example

Group command

groups View the current group ,newgrp Create a new group

User command

useradd Create user ,passwd Change Password ,chage Show password details

usermod Modify user information , userdel Delete user

Acl jurisdiction

Getfacl, setfacl

User identity switching

su Switching users , sudo simulation root To operate , Very useful , For example, install software

sudo apt install xxx

pam modular

Pluggable Authentication Modules For user authentication

Information Service

w, who Get account login information ,last,lastlog

Next , Introduce linux Some advanced concepts about file systems .

Disk quota Quota: Used to manage the disk size available to each user , Including a hard Threshold and a soft threshold .

Software disk array Software RAID: such as RAID-0 Best performance ,RAID-1 Full backup ,RAID-0+1 Balance performance and backup ,RAID-5 Pass the parity check code parity To balance performance and security , Any one of the disks is damaged , Can be recovered , adopt /etc/madadm.conf To configure .

Logical volume manager LVM(Logical Volume Manager): involve 5 The main concepts ,PV Represents a physical volume ,VG Represents the volume user group ,PE Represents a physical expansion block ,LV Represents a logical volume .

Tip: Now popular Docker It's built on LXC Container engine on , This part needs to be strengthened .

Our common Job Types work in Linux Known as crontab Routine tasks , Common routine work in the system includes : Rotation of log files , Log file analysis Logwatch Mission , newly build locate database ,whatis The establishment of database ,RPM Software log file creation , Delete temporary files , Analytical behavior related to Web Services .

Work performed only once :/etc/init.d/atd restart, chkconfig atd on, at now + 5 minutes

Cyclic routine work :59 23 1 5 * mail tete < /home/xionger/lover.txt Email your girlfriend every year , System profile /etc/crontab

Later on Linux Process management of ,Linux The process of development also includes Process control block PCB And the data section , The former includes PID Information about permissions , The data section contains the code and related information needed by the program , The relevant commands for its management are as follows .

command

Example

Work management

Jobs View current work ,kill –pid Shut down the background process

Process view

ps aux, ps aux | egrep '(cron|syslog)'

top Dynamic view of process changes

pstree View the process tree

ps aux | grep 'syslog' | grep -v 'grep' | awk '{print $2}'

killall -9 httpd Terminate all with httpd The process started

Process priority

ps -l, nice, renice [number] PID

View of system resources

free View memory information ;uname View kernel information ;

uptime View system startup time and workload

netstat: Tracking the Internet

Other commands :dmesg, vmstat

cat /etc/services

Finally, it introduces , I think it's more important System service and log analysis part . stay Linux in ,daemon Background processes ( That is service ) Contains two categories , One is stand_alone Of , One is by super daemon Unified management . Generally speaking , Each service has a specified port , such as http Service 80 port ,ftp Service 21 port . The startup script for the service will be placed in /etc/init.d/* in , The relevant initialization configuration file is placed in /etc/sysconfig/* in ,super daemon The configuration file of is in /etc/xinetd.conf,/etc/xinetd.d/* in , The configuration file of the service itself is placed in /etc/* in , The data generated by the service is placed in /var/lib/* in , Service PID It's recorded in /var/run/* in . Can pass service xxx restart Start the service , adopt service --status-all View service status .

Tip: It can be modified by /etc/hosts.allow and /etc/hosts.deny To set white / The blacklist .

stay Linux in , Common log files are usually in /var/log/ Catalog , cron Scheduling logs for work ,dmesg Detect information for the kernel ,lastlog Last login information of all accounts ,maillog Email related information (SMTP, POP3),messages System error message ,secure Login related security information ,httpd Network service information .

So what's the service for logging ?syslogd, You can view the following commands :ps aux | grep syslog, chkconfig --list syslog, To protect log files , We can go through chattr –a To achieve . Besides , The rotation of logs is through logroate Services to achieve , Its profile is /etc/logrotate,conf,/etc/logrotate.d All files in the directory will be read into the configuration .( Pay attention to Ali cloud ,ubuntu14.0.0, be-all syslog All become rsyslog).

Besides ,linux Common log analysis tools include logwatch, You can send the analysis report to your email regularly , If further custom analysis is needed , You can refer to the information then .

" People live to realize what they have blown ' frigging awesome '"-- anonymous

Reference material :

  1. Bird brother . Bird brother Linux Basic study of private dishes ( The third edition )[M]. Beijing : People's post and Telecommunications Press , 2010.

Linux Quick start 03- More articles on system management

  1. Linux Quick start opens your way to learning

    Linux Quick start opens your way to learning I believe you want to learn from this article Linux, Or already learning Linux Of people , Then we can discuss , Study Linux How to get started quickly ? First , I hope you can find out why you are ...

  2. Linux Quick start tutorial - Process management ipcs Command learning

    Use Linux One of the necessary skills of the system is Linux Process management , The process of system running is just the process of countless processes running . The running of these processes needs to occupy the system's memory and other resources , Do a good job of system process management , For us to distribute reasonably . It's very meaningful to use system resources ...

  3. Linux Quick start 02- File system management

    Continue to enter Linux File system learning , come on. , Early breakthrough MS The bondage on myself . Linux Series articles Quick start series --Linux--01 Basic concepts Quick start series --Linux--02 File system management Quick start Department ...

  4. Linux Quick start 01- Basic concepts

    4 Years ago , I just came to Shanghai times to talk about Oracle The training course of , There I came into contact with Linux, But I never really tried to use it . Now, after a slow growth , More and more ,Linux It is a system that every server engineer must master , Even now the most ...

  5. Linux Quick start 04- Expanding knowledge

    This is the last part of fast learning , One of the most important content is the source code packaging and software installation learning , Because of personal Linux The purpose of learning is to be in alicloud Ubuntu Build a simple nodejs Release environment . Linux Series articles ...

  6. NOI Linux Quick Start Guide

    Catalog About installation NOI Linux The system configuration The Internet typewriting Editor 1. gedit open To configure Appearance display 2. vim open To configure Use makefile Compile operation 1. To write makefile 2 ...

  7. linux Quick start 1.1 Command line operations

    http://lovesoo.org/linux-command-line-operation.html 1.1 Command line operations Catalog : <wp_nokeywordlink>Shell brief introduction &l ...

  8. Linux Quick start

    One .Linux Introduce 1.Linux Is based on Unix Open source free operating system 2.Linux The classification of : (1)Linux According to the market demand , There are basically two directions : 1) Graphical interface version : Focus on user experience , similar window operation ...

  9. Linux System quick start method

    I believe you want to learn from this article Linux, Or already learning Linux Of people , Then we can discuss , Study Linux How to get started quickly ? First , I hope you can find out why you want to learn Linux, Some people are interested in ...

Random recommendation

  1. solve IE7 and IE6 I won't support it javaScript Medium indexOf Function problem

    I'm here for two strings , If it's a character array, it's about the same , The code is as follows : function indexCheck(str, sortStr) { str = String(str);// Let's deal with the parameters , Avoid numbers ...

  2. php utf-8 Character conversion ascii character

    function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\ ...

  3. pentaho cde Data linkage , A drop-down box , The text box , graphics

    Let's take a look at the effect : Open source bi Tools pentaho Data linkage , Unlike changing data in the traditional sense ,pentaho cde You need a monitor to transfer values dynamically . Let's talk about some points that need attention 1. Parameters cannot be passed directly in two charts , must ...

  4. webService send out soap request , And parse the returned soap message

    This application scenario : Make one webService Testing capabilities , Not limited to any fixed format webService, So it's like axis,cxf Wait for the frame to work . Only go deep into webService Principle , By sending and receiving soap message , ...

  5. CodeForces 505B Mr. Kitayuta&#39;s Colorful Graph

    Mr. Kitayuta's Colorful Graph Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  6. 【SSMS Enhancement tool 】SQL Sharper 2014 Introduce

    Product introduction SQL Sharper Is a SQL Server Management Studio plug-in unit , Used for quick query of database objects . Table structure query . Optimize query result export . Code generation and so on . Applicable people :T-SQL developer . ...

  7. Linux File packaging and decompression

    One . File packaging and decompression Common compressed package file formats . stay Windows The most common ones are the three *.zip,*.rar,*.7z The suffix of the compressed file , And in the Linux In addition to the above three kinds , also *.gz ...

  8. 1001. [BJOI2006] The wolf catches the rabbit 【 Minimum cut 】

    Description Now children's favorite " Pleasant goat and grey wolf ", Gray wolf can't catch sheep , But catching rabbits is better , And the rabbits are stupid now , They only have two nests , Now you're the wolf king , In the face of the following ...

  9. You can also draw a QR code by hand ( Two ) Error correcting codeword algorithm : The basis of number theory and Galois field GF(2^8)

    Abstract : This paper explains the basic knowledge of mathematical number theory used in two-dimensional code error correction codeword generation , Galois domain (Galois Field)GF(2^8), This is the theoretical basis of hand-painted two-dimensional code filling grid , If you don't want to go deep, you can just skip . At the same time, the basis of number theory is also Hash Algorithm ,RS ...

  10. MT【137】 How many? ?

    The sequence \(\{a_n\}\) common 11 term ,\(a_1=0,a_{11}=4\), And \(|a_{k+1}-a_{k}|=2,k=1,2,\cdots,10\) Find the number of different sequences that satisfy the condition ______ answer : ...