1. Install Linux

Because the figure is too much, reprint a detailed installation tutorial from virtual machine vmware configuration to Centos7

https://www.cnblogs.com/wcwen1990/p/7630545.html

2. Common Linux commands

2.1 Common Directories

/bin

Store binary executable files (ls,cat,mkdir, etc.), commonly used commands are generally here.

/etc

Stores system management and configuration files

/home

The root directory that stores all user files is the base of the home directory of a user. For example, the home directory of user is /home/user, which can be represented by ~user

/usr

Important directory /usr/local Local system administrator software installation directory (for installing system-level applications). This is the largest directory and contains almost all the applications and files to be used.

/usr/x11r6 Specifies the directory where the X window is stored

/usr/bin many applications

Some hypervisors for the /usr/sbin superuser

The/usr/doc Linux documentation

Header files needed to develop and compile applications under /usr/include Linux

/usr/lib Commonly used dynamic link libraries and software package configuration files

/usr/man help documentation

/usr/src source code, Linux kernel source code is in /usr/src/Linux

/usr/local/bin Local added command

/usr/local/lib Locally added libraries

/opt

Placement of optional application packages for additional installations. Normally, we can install Tomcat and so on here.

/proc

A virtual file system directory is a mapping of system memory. You can access this directory directly to get system information.

/root

Home directory of the superuser (system administrator) (privileged class ^o^)

/sbin

Stores binary executable files, which can only be accessed by root. This is where the system-level administrative commands and programs used by the system administrator are stored. Such as ifconfig.

/dev

Used to store device files.

/mnt

The installation point for a system administrator to install a temporary file system. This directory is provided by the system for users to temporarily mount other file systems.

/boot

Stores the various files used for system boot

/lib

Stores shared libraries and kernel modules needed to run programs in the file system. Shared libraries, also known as dynamically linked shared libraries, are similar to.DLL files in Windows. They contain shared files needed by the root file system to run programs.

/tmp

Used to store a variety of temporary files, is a public temporary file storage point.

/var

Files that hold data that needs to be changed at run time are also overflow areas for some large files, such as log files for various services (system startup logs, etc.). And so on.

/lost+found

This directory is normally empty, but the system unexpectedly shut down and left the “homeless” file (what’s called.chk in Windows) here

2.2 Basic Command Formats

2.2.1 Command Prompt

[root@xiaoming ~]#
Copy the code
  • Root Indicates the current login user
  • Host name localhost.
  • ~ Current working directory. The default is the home directory of the current user. Root is /root, and common user is /home/user
  • The prompt is # for superuser and $for normal user

2.2.2 Syntax of the command

  • Command [Options] [Parameters]
  • When you have multiple options, you can write them together
  • General parameters have two kinds of simplified and complete writing-a--allequivalent

2.2.3 the ls

  • Query the contents of a directory
  • Ls [options] [file or directory]
  • options
    • -a Displays all files, including hidden files
    • -l Displays detailed information
    • -d Displays the properties of the directory itself instead of the subfile ls /etc//etc/
    • -h Displays the file size in a user-friendly way
    • -i Displays the inode, which is the I node. Each node has an ID
  • The default list of files in the current directory
 -l

Display details

drwxr-xr-x .  1 root  root   800 Sep 16 00:19 logs
Copy the code
drwxr-xr-x . 1 root root 800 Sep 16 00:19 logs
File types and permissions ACL Hard link reference counting The owner of the Subordinate to the group The file size Last modified time The file name
File types and permissions
-rw-r--r--
Copy the code
  • File Type – File, d directory, l Soft link file
  • U (owner), G (group), O (others)
  • R (read) reads, w(write) writes, and x(execute) executes

2.3 File Processing commands

2.3.1 mkdir

  • Make directory
  • Mkdir -p [directory name]
    • -P is created recursively

2.3.2 CD

  • Change directory
  • CD [directory]
    • To the home directory
    • The home directory
      • The last directory
    • . Current directory
    • . The higher the directory
  • The relative path refers to the current directory
  • The absolute path starts at the root directory
  • Press TAB to complete commands and directories

2.3.3 the PWD

  • Display current directory PWD

2.3.4 rmdir

  • Delete the remove empty directory directory
  • Rmdir [directory name]

2.3.5 rm

  • Remove a file or directory
  • Rm [file or directory]
    • -r Deletes a directory
    • -f Forcibly deletes the file
  • Rm -rf files or directories] deletes all directories recursively

2.3.6 cp

  • Copy Replication command
  • Copy [source file or directory] [Destination file]
    • -r Copies directories. By default, copies files
    • -p Copy file attributes
    • -d If the source file is a link file, the connection properties are copied
    • -A is equal to -rpd

2.3.7 mv

  • Move files or rename move
  • Mv [source file or directory] [Destination file]

2.3.8 ln

  • Link command to generate a link filelink
2.3.8.1 Hard link Feature
  • Having the same I node and storage blocks can be regarded as the same file
  • It can be accessed through the I node
  • Cannot cross partitions
  • Cannot be used for directories
  • Generally not used
2.3.8.2 Soft link Feature
  • Ln -s [source file] [Destination file]
    • -s Creates a soft link
  • Similar to Windows shortcut
  • The soft link has its own I node and Block, but the data Block only holds the file name and I node number of the source file, not the actual file data
  • LRWXRWXRWX L Soft link The file permissions for soft links are 777
  • Modifying one file will change the other
  • The soft link cannot be used because the source file is deleted
  • The soft link source file must be written to an absolute path

2.4 File search commands

Against 2.4.1 locate

  • In the background database search by file name, the speed is faster
  • Data is stored in/var/lib/mlocateBackground database, updated once a day
  • canupdatedbCommand to update the database immediately
  • Only file names can be searched
  • /etc/updatedb.confThe profile for creating the index
    • PRUNE_BIND_MOUNTS = “yes” Both take effect, enabling search restrictions
    • PRUNEFS The file system that is not searched
    • PRUNENAMES Specifies the type of file that is ignored
    • PRUNEPATHS ignored path/TMP

Whereis 2.4.2

  • Search command path and help document location
  • Whereis the command namewhereis ls
    • -b Searches only executable files
    • -m Searches for help files only

2.4.3 which?

  • You can see the aliaswhich ls
  • All you can see are externally installed commands
  • The commands provided by the Shell cannot be viewed, for examplewhich cd

2.4.4 Environment variables

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

  • Defines the path to the system search command
  • echo $PATH

2.4.5 find

  • File search command
  • Find [search scope] [Search criteria]
2.4.5.1 Searching by Name
  • Avoid extensive searches, which are a drain on system resources
    find / -name aaa.log
    Copy the code
2.4.5.2 wildcard
  • Find searches the system for the file names that match the conditions. If a match is required, use the wildcard character to match the file names. The wildcard character is an exact match
  • The wildcard
    • *Match any content
    • ?Matches any character
    • []Matches any character in brackets
find . -name "ab[cdef]"
Copy the code
2.4.5.3 -i

Case insensitive

find / -iname A.log
Copy the code
2.4.5.4 – user

Search by owner

find /root -user root
find /root -nouser
Copy the code
2.4.5.5 Search by Time
find /nginx/access.log -mtime +5
Copy the code
parameter meaning
atime File access time
ctime Changing file Properties
mtime Modifying file Contents
parameter meaning
– 5 Files modified within 5 days
5 File that was modified five days ago
+ 5 The file was modified five days ago
2.4.5.6 Search by Size
  • K lowercase,M uppercase
find . -size 100k
Copy the code
parameter meaning
-8k Less than 8 k
8k Equal to 8 k
+8k More than 8 k
+8M Less than 8 m
2.4.5.7 Search by I node
find . -inum 123456
Copy the code
2.4.5.8 Comprehensive Applications
find /tmp -size +10k -a -size -20k
Copy the code
  • Look for files in /etc directory that are larger than 10KB and smaller than 20KB
  • -a and logic and, both conditions are satisfied
  • -o or Logic or, if one of the two conditions is met
find /tmp -size +10k -a -size -20k -exec ls -lh {} \;
Copy the code
  • Exec operates on the result of the previous command
2.4.5.9 grep
  • Matches the string that matches the condition in the file
  • grep “10” access.log
    • -iIgnore case
    • -vExclude specified string
  • The find command is used to search for the file name that meets the requirements. If the file name needs to be matched, use the wildcard character. The wildcard character is an exact match
  • Run the grep command to search for a string that meets the requirements in the file. If a match is required, use regular expressions to match the string. The regular expressions contain matches

2.5 Help Commands

2.5.1 Basic Usage

  • Man command to obtain help information about a specified command
  • man lsView the help of ls
man -f ls
whatis ls
man 1 ls
man 1p ls
Copy the code

2.5.2 Keyword Search

- man -k passwd
Copy the code

2.5.3 Shell internal Help

  • whereisFind is outside, don’t find is inside
    help cd
    Copy the code

2.6 Compression and Decompression Commands

.zip .gz .bz2 .tar.gz .tar.bz2

2.6.1 zip format

  • Zip Compressed file name Source file
  • Zip -r Source directory of the compressed file name
  • Decompress the unzip file name
    mkdir book
    touch book/1.txt
    touch book/2.txt
    zip -r book.zip book
    unzip book.zip
    Copy the code

2.6.2 gzip

The command The sample meaning
Gzip source file gzip a.txt Gz compressed file, the source file will disappear
Gzip -c Source file > compressed file gzip -c yum.txt > yum.txt.gz Gz compressed file. The source file does not disappear
Gzip -r directory gzip -r xx Compresses all subfiles in a directory, but does not compress the directory
Gzip -d Indicates the compressed file name gzip -d yum.txt.gz Decompress the file without retaining the compressed package
Gunzip Compressed file gunzip yum.txt.gz Decompress the file without retaining the compressed package
  • Compression is the compression of files in the directory

2.6.3. Bz2 format compression

The command The sample meaning
Bzip2 source file bzip2 1.txt Compress the file to. Bz2 format without retaining the source file
Bzip2 -k Source file zip2 -k 1.txt Compress the file to. Bz2 format, keeping the source file
Bzip2 -d Compressed file name bzip2 -d 1.txt.bz2 Decompressing a Compressed Package
Bunzip2 Compression file name bunzip2 1.txt.bz2 Decompressing a Compressed Package
  • Bzip2 does not compress directories

2.6.4 tar

  • Packaging orders
  • Tar -cvf Package file name source file
    • – c packaging
    • -v Displays the process
    • -f Specifies the file name of the package
tar -cvf book.tar book
gzip book.tar
bzip2 book.tar
Copy the code
  • X solution package
    tar -xvf book.tar
    Copy the code

2.6.4 Compression Format

The compression

Tar — CVF jpg.tar *.jpg — CZF jpg.tar.gz *.jpg — CZF jpg.tar *.jpg Gz tar — CJF jpg.tar.bz2 *.jpg // Package all JPG files in the directory into jpg.tar and compress them with bzip2 to generate a bzip2-compressed package. Bz2 tar -czf jpg.tar.z *.jpg // Pack all JPG files in the directory into jpg.tar and compress them with compress to generate a umcompress compressed package. Zrar a jpg.rar *. JPG // To compress the file in the rar format, download RAR for Linux zip jpg.zip *

Unpack the

Tar -xvf file.tar // Decompress the tar package tar -xzvf file.tar.gz // Decompress tar.gz tar -xjvf file.tar.bz2 // Decompress tar.bz2 tar -xzvf file.tar.z // Unzip tar.Z unrar e file.rar // Unzip rar unzip file.zip // Unzip zip

2.7 Shutdown and Restart commands

2.7.1 shutdown

Shutdown command

  • -c Cancel the previous shutdown command
  • -h shutdown
  • – r to restart
    shutdown -r 06:00
    shutdown -c
    Copy the code

2.7.2 init

To turn it off

init 0
Copy the code

restart

init 6
Copy the code

The system runlevel

  • 0 to turn it off
  • 1 but users
  • 2 Incomplete multiple users, excluding the NFS service
  • 3 Fully multi-user
  • 4 undistributed
  • 5 Graphical Interface
  • 6 to restart

2.7.3 logout

Log out

logoutCopy the code

2.9 Viewing The Login User Information

2.9.1 w

View the login user information

  • USER USER name for login
  • Tty1 Local terminal PTS /0 Remote terminal
  • FROM IP address for login
  • LOGIN LOGIN time
  • IDLE Indicates the IDLE time of the user
  • JCPU Time occupied by all processes on the terminal
  • PCPU Indicates the time occupied by the current process
  • WHAT is the command being executed

2.9.2 the who

View the login user information

  • USER USER name for login
  • Tty1 Local terminal PTS /0 Remote terminal
  • LOGIN LOGIN time (LOGIN IP address)

2.9.3 last

View information about current and past login users. By default, /var/log/wtmp is read

  • The user name
  • Log on to the terminal
  • The login IP
  • The login time
  • Exit time (Online time)

2.9.4 lastlog

View the last login time of all users

  • The user name
  • Log on to the terminal
  • The login IP
  • Time of last login

3. shell

  • The shell is a command-line interpreter that provides users with an interface system-level program that sends requests to the Linux kernel in order to run programs
  • Users can use the Shell to start, suspend, stop, or write programs
  • Shell is also a powerful programming language, easy to write, easy to debug, strong flexibility.
  • The Shell is a scripting language that interprets execution. You can call Linux system commands directly from the Shell.

3.1 Viewing Supported Shells

  • /etc/shells

3.2 the echo

  • The output command
  • –e Supports backslash controlled character conversion
Control characters role
\a Output warning tone
\b Backspace, or delete to the left
\n A newline
\r The enter key
\t Tab, Tab key
\v Vertical TAB
\onnn Output characters in octal ASCII code tables, where 0 is the digit zero and NNN is a three-digit octal number
\xhh Output characters according to the hexadecimal ASCII code table, where hh is a two-digit hexadecimal number

3.3 Writing and executing shell

#! /bin/bash
echo -e "\e[1;34m hello world \e[0m"
Copy the code

Grant execute permission and run directly

chmod 755 hello.sh
./hello.sh
Copy the code

Execute the script through Bash calls

bash hello.sh
Copy the code

3.4 the alias

  • Command alias == Petty name
  • Temporary effect
  • alias
  • alias rm=”rm -i”
  • Write the environment variable configuration file vi ~/.bashrc
  • source ~/.bashrc
  • Unalias Alias Deletes an alias

3.5 Effective Order of the Commands

  • Absolute path or relative path
  • The alias
  • Bash internal commands
  • The first command found in the directory lookup order defined by the $PATH environment variable

3.6 Command Shortcut Keys

The command meaning
ctrl+c Forcibly terminates the current command
ctrl+l Clear the screen
ctrl+a The cursor moves to the beginning of the command line
ctrl+e The cursor moves to the end of the command line
ctrl+u Delete from the cursor position to the beginning of the line
ctrl+z Put the command in the background
ctrl+r Search in the history command

3.7 Historical Commands

  • History [option] [History command save file]
  • options
    • -c Clears history commands
    • -w Writes the history commands in the cache to the history command saving file ~/.bash_history
  • By default, 1000 entries are saved. /etc/profile HISSIZE=10000

3.8 call

  • Use the up and down arrows to invoke the previous history command
  • Use! N Repeat the NTH history command
  • Use!!!!! Repeat the previous command
  • Use! Character repeats the last command starting with the string

3.9 Pipe Symbols

3.9.1 Executing Multiple Commands In Sequence

(1); Semicolon, a hyphen without any logical relationship. When multiple commands are connected with semicolons, the execution of each command has no effect on the other.

(2) | | logic or, when using this connector to connect multiple command, command execution, success in front of, behind the command does not executed. The preceding command is executed only when the preceding command fails.

(3) && logic and, when using this connector to connect multiple commands, the previous command execution success, will perform at the back of the command, command execution fails, in front of the back of the command does not executed, and | | just the opposite.

(4) | pipe, when using this connector to connect multiple command, command execution in front of the output correctly, will be handed over to the back of the order to continue processing. If the preceding command fails to execute, an error is reported. If the following command fails to process the output of the preceding command, an error is also reported.

- date; ls; date; ls - ls &&echo yes || echo no
Copy the code

3.9.2 Pipe symbols

  • The correct output of command 1 is used as the operation object of command 2
  • Command 1 | 2
    ls /etc/ | more
    netstat -an | grep ESTABLISHED | wc -l
    Copy the code

3.9.3 wildcard

Match the file name and directory name role mask | | | | : – | – – | |? Matching an arbitrary character | | | * | match zero or any character, also can match any content is | | | [] matches any character in the brackets | | | [-] matches any character in the brackets, – on behalf of the scope of | | | [^] match is not a character | in brackets

3.9.4 Other symbols

symbol role
‘ ‘ Single quotation marks. All the special symbols in single quotes, such as $and ‘, have no special meaning
“” Double quotes, special symbols in double quotes have no special meaning, except for $’ \, which has the meaning of calling variable values, quoting commands, and escaping
The backquote, which is extended, is the system command
The $() Same as back quotes
# In shell scripts, lines beginning with # represent comments
$ The value used to call the variable
\ Escape symbol
-  a=`ls`
-  b=$(ls)
Copy the code

4. Use the vi editor

  • VI visual interface
  • Visual interface
  • Similar to Notepad in Windows
  • Vim supports multi-level undo
  • cross-platform
  • Syntax highlighting
  • Graphical interface support

4.1 Operation Mode

  • Save: w
  • : q exit
  • :! Mandatory saving
  • :ls lists all files
  • A: n
  • A: N
  • :15 Jumps to the specified line
  • / XXX Searches the XXX string backwards from the cursor position
  • ? XXX searches forward from the cursor position

5. Users and user groups

  • Everyone who uses an operating system is a user
  • A user group is a group of users with the same system permissions

5.1 user group

5.1.1 the/etc/group

  • /etc/group Stores information about all user groups in the current system
  • group:x:123:abc,def
  • Group name: Group password Placeholder: Group number: user name list in the group
  • The root group number is 0
  • 1-499 System reserved number Reserved for the software and services to be installed
  • Manually created user groups start from 500
  • The group password placeholder is x

5.1.2 the/etc/gshadow

  • Stores the passwords of user groups in the current system
  • Corresponds to the records in the group
  • Group: * : :abc
  • Group Name Group Password Group Administrator group username

5.1.3 / etc/passwd

  • Stores information about all users in the current system
  • user:x:123:456:xxxxx:/home/user:/bin/bash
  • User name: Password Placeholder: User number: user Comment information: User home directory :shell type

5.1.4 ensuring the/etc/shadow

  • Stores the passwords of all users in the current system
  • user:xxx:::::::
  • Username: Password:

6. User operations

Add the group

groupadd student
Copy the code

Changing a Group Name

groupmod -n stu student 
Copy the code

Changing the Group Number

groupmod -g 111 stu 
Copy the code

Add a group and specify a number

groupadd -g 222 teacher 
Copy the code

Delete the group

groupdel 222 
Copy the code

Add a group

groupadd teacher 
Copy the code

Specifies a owning group for the user

useradd -g teacher zhangsan 
Copy the code

Specifies a owning group for the user

useradd -g teacher lisi 
Copy the code

Specify a working directory for the user

useradd -d /home/zhangsan zhangsan 
Copy the code

Specify the annotation

usermod -c iamateacher zhangsan 
Copy the code

Changing a User Name

usermod -l zhangsan zhangsan2
Copy the code

Specify folder

usermod -d /home/zhangsan2 zhangsan2 
Copy the code

Example Modify the owning group of a user

usermod -g stu zhangsan2 
Copy the code

Delete user

userdel zhangsan2 
Copy the code

Deleting a Owning Folder

userdel -r lisi 
Copy the code

7. User commands

Displays the login user name

whoami
Copy the code

Displays the information about the specified user, including the user number, user name, number and name of the primary group, and the list of secondary groups

id zhangsan  
Copy the code

All groups to which user Zhangsan belongs are displayed

groups zhangsan 
Copy the code

Display user details

finger zhangsan  
Copy the code

8. The appendix

8.1 System Startup

8.1.1 BIOS

  • When the computer is powered on, the first thing to do is to read the boot program which is flushed into the ROM chip. This program is called (Basic Input/Output System).

8.1.2 Hardware Self-check

  • The BIOS program first checks whether the computer hardware meets the basic conditions for running. This is called a “power-on self-test.”
  • If there is a hardware problem, the motherboard will emit a different meaning of the buzzer, startup abort. If there are no problems, the screen displays CPU, memory, hard disk, and so on.

8.1.3 Startup Sequence

  • After the hardware self-test is complete, the BIOS transfers control to the next stage of the startup program.
  • At this point, the BIOS needs to know, “where is the next stage of startup” stored
  • The BIOS needs to have a sequence of external storage devices, with the first device in the list being the first to transfer control. This sort is called a Boot Sequence.
  • The BIOS transfers control to the first storage device in boot order.
  • At this point, the computer reads the device’s first sector, the first 512 bytes. If the last two bytes of the 512 bytes are 0x55 and 0xAA, the device is ready for startup; If not, the device cannot be used for boot, and control is transferred to the next device in the “boot sequence”.
  • The first 512 bytes are called the “Master Boot Record.”

8.1.4 Structure of the master boot record

  • The master Boot record is only 512 bytes. It doesn’t hold much. Its main function is to tell the computer where to find the operating system on the hard disk.
    • (1) Bytes 1-446: is used to record the system startup information, call the operating system machine code
    • (2) Bytes 447-510 (64 bytes) : The Partition table is used to divide a hard disk into partitions
    • (3) Bytes 511-512: Master boot record signature (0x55 and 0xAA)

8.1.5 partition table

  • Disk partitioning is the partitioning of logical parts of the disk using a partition editor
  • Once a disk is divided into multiple partitions, directories and files of different classes can be stored in different partitions
  • The Master boot record must therefore know which sector to transfer control to
  • The partition table is only 64 bytes long and is divided into four 16-byte entries. Therefore, a hard disk can be divided into at most four primary partitions, also known as primary partitions
    • (1) The first byte: 0x80 indicates that the primary partition is the active partition and control is transferred to this partition. Only one of the four primary partitions can be active.
    • (2) Bytes 2-4: the physical location of the first sector of the primary partition (cylinder, head, sector number, and so on).
    • (3) The fifth byte: the primary partition type, such as FAT32, NTFS, etc.
    • (4) Bytes 6-8: the physical location of the last sector of the primary partition.
    • (5) Bytes 9-12: the logical address of the first sector of the primary partition.
    • (6) Bytes 13-16: total number of sectors in the primary partition.

8.1.6 Starting a Hard Disk

  • Control of the computer is about to be transferred to a partition on the hard drive
  • Of the four primary partitions, only one is active. The computer reads the first sector of the activated partition, called a Volume Boot Record (abbreviated VBR)

8.1.7 Operating System

  • After control is transferred to the operating system, the kernel of the operating system is first loaded into memory.
  • On Linux, for example, load it first/bootsubdirectorykernel. After the kernel is successfully loaded, the first program to run is/sbin/init. It generates init processes based on the configuration file (/etc/initab on Debian). This is the first process after Linux starts, the PID process is numbered 1, and all the other processes are its descendants
  • And then,initThreads load the various modules of the system, such as Windows and network programs, until they are executed/bin/loginProgram, jump out of the login interface, waiting for the user input user name and password.