1. Linux

  • Linux is a free to use and freely distributed UniX-like operating system
  • In the field of server and embedded field has a very wide range of applications

Version 2.

There is a kernel version and a hairstyle version

  • kernel
  • Each manufacturer produces its own distribution
    • redhat
    • CentOS
    • ubuntu
    • fedora

3. Differences between Linux and Windows

  • Linux is case-sensitive
  • Everything in Linux is saved as a file, including hardware, users, and files.
  • Linux does not differentiate between file types by extension, but by permission, but there are some convention extensions for administrators
    • Compressed package.gz .bz2 .tar.bz2 .tgz
    • Binary file.rpm
    • Web page file.html .php
    • The script file.sh
    • The configuration file.conf
  • Windows programs cannot be installed and run directly in Linux
  • Linux uses more character interfaces
    • It consumes fewer system resources
    • Reduce the possibility of error and attack, will make the system more stable

3. Purchase a server

  • Ali cloud ECS
  • Tencent cloud CVM
  • Amazon AWS
  • Baidu cloud

4. Connect to the server

  • git bash
  • mac shell
  • xshell4
  • xftp4

5. Common Linux commands

5.1 Common Directories

directory use
/ The root directory
/boot Start directory, start related files
/dev Device file
/etc The configuration file
/home Common user home directory, can operate
/lib System library saving directory
/mnt Mobile device mount directory
/media Directory for mounting the CD-ROM
/misc Directory where the tape drive is mounted
/root Home directory of the superuser that can be operated
/tmp Temporary directory that can be operated
/proc A running kernel information map that outputs process information, memory resource information, disk partition information, and so on
/sys Hardware device driver information
/var variable
/bin Common basic commands, such as ls and chmod, can also be used by ordinary users
/sbin Basic system commands, such as shutdown and reboot, are used to start the system and repair the system. Only administrators can run them
/usr/bin Is a running script for some software that you install later
/usr/sbin Place a few user-installed system administration prerequisites

5.2 Basic Command Formats

5.2.1 Command Prompt

[root@james ~]#
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

5.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

5.2.3 requires 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
  • The default list of files in the current directory
ls -l
Copy the code
5.2.3.1 l.

Display details

drwxr-xr-x  root  root   800 Sep 16 00:19 logs
Copy the code
drwxr-xr-x root root 800 Sep 16 00:19 logs
File types and permissions The owner of the Subordinate to the group The file size Last modified time The file name

5.3 File Processing commands

5.3.1 mkdir

  • Make directory
  • Mkdir -p [directory name]
    • -P is created recursively
mkdir -p hello
Copy the code

5.3.2 CD

  • Change directory
  • CD [directory]
    • To the home 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
cd hello
Copy the code

5.3.3 the PWD

  • Display current directory PWD
pwd
Copy the code

5.3.4 rmdir

  • Delete the remove empty directory directory
  • Rmdir [directory name]
rmdir hello
Copy the code

5.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
rm -rf hello
Copy the code

5.3.6 cp

  • Copy Replication command
  • Copy [source file or directory] [Destination file]
    • -r Copies directories. By default, copies files
    • -i will prompt you when copying the file, and if the target file exists, it will prompt you whether to overwrite it
mkdir afolder
mkdir bfolder
cd afolder/
touch 1.txt
cp 1.txt ~/bfolder/
Copy the code

5.3.7 mv

  • Move files or rename move
  • Mv [source file or directory] [Destination file]
mv 1.txt 11.txt
Copy the code

5.3.8 ln

  • Link command to generate a link filelink
  • Ln -s [source file] [Destination file]
    • -s Creates a soft link
  • Similar to Windows shortcut
  • 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
# ln -s /root/bfolder/11.txt 22.txt
Copy the code

5.4 File Search commands

5.4.1 locate

  • In the background database search by file name, the speed is faster
  • Data is stored in/var/lib/mlocate/mlocate.dbBackground database, updated once a day
  • canupdatedbCommand to update the database immediately
  • Only file names can be searched
yum  -y install mlocate
Copy the code

5.4.2 whereis

  • Search command path and help document location

  • Whereis the command name

    whereis ls
    Copy the code
    • -b Searches only executable files
    • -m Searches for help files only
  • You can check out the commands that come with the Shell, such as whereis CD

5.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

5.4.4 Environment Variables

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Copy the code
  • Defines the path to the system search command
  • echo $PATH

5.4.5 find

  • File search command
  • Find [search scope] [Search criteria]
5.4.5.1 Searching by Name
  • Avoid extensive searches, which are a drain on system resources

    find / -name 11.txt
    Copy the code
5.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
# touch abc.txt
# find . -name "ab[cdef].txt"
Copy the code
5.4.5.3 -i
  • Case insensitive
find . -iname "Ab[cdef].txt"
Copy the code
5.4.5.4 – user
  • Search by owner
find /root -user root
find /root -nouser
Copy the code
5.4.5.5 Search by time
find . -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
5.4.5.6 Search by Size
  • K lowercase,M uppercase
find . -size +0k
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
5.4.5.7 Comprehensive application
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
5.4.5.9 grep
  • Matches the string that matches the condition in the file
    • -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
vi a.txt
grep b a.txt
grep -v b a.txt
grep -i f a.txt
Copy the code

5.5 Compression and Decompression Commands

5.5.1 zip format

  • A compressed file or directory is a compressed format
function The command
The compressed file Zip File name. Zip Source file
Compressed directory Zip -r Specifies the name of the compression directory. Zip Specifies the source directory
Unpack the Unzip Specifies the name of the compression directory. Zip
yum install -y unzip zip

mkdir book
touch book/1.txt
touch book/2.txt
zip -r book.zip book
rm -rf book/ rmdir book
unzip book.zip
Copy the code

5.5.2 gzip

  • Gzip is high pressure and can compress files even smaller
  • The gzip command does not support directories
The command The sample meaning
Gzip source file gzip book.txt Gz compressed file, the source file will disappear
Gzip -c Source file > compressed file gzip -c book.txt > book.txt.gz Gz compressed file. The source file does not disappear
Gzip -r directory gzip -r book Every subfile in the directory is changed into a compressed package, and the original file is deleted. The current directory remains unchanged
Gzip -d Indicates the compressed file name gzip -d 1.txt.gz Decompress the file without retaining the compressed package
Gunzip Compressed file gunzip 2.txt.gz Decompress the file, and do not keep the compressed package
  • Compression is the compression of files in the directory
touch book.txt
mkdir book
touch book/1.txt
touch book/2.txt
gzip book.txt // The source file will disappear
gzip -c 1.txt > 1.txt.gz // The source file does not disappear
gzip book.txt  // Compress the file to. Gz format. The source file will disappear
gzip -r book // Turn each subfile in the directory into a zip package
cd book
gzip -d 1.txt.gz  // Decompress the file without retaining the compressed package
gunzip 2.txt.gz 
Copy the code

5.5.3 tar

  • Package command, only package without compression

  • tar -cvf
    Copy the code

    Package file name Source file

    • – c packaging
    • -v Displays the process
    • -f Specifies the file name of the package
tar -cvf book.tar book    // A book.tar file is packaged
Copy the code
  • X unlock package

    tar -xvf book.tar 
    Copy the code

5.5.4 tar.gz Compression format

  • zipDirectories can be compressed but not efficiently,gzipHigh compression efficiency but does not support directories
  • Can be packaged as.tarFormat, and then compressed into.gzGz format. -x Decompresses the. Tar. gz format
The command The sample meaning
Tar -zcvf Specifies the compressed package name.tar.gzThe source file tar -zcvf book.tar.gz book Can be packaged as.tarFormat, and then compressed into.gzformat
Tar -zxvf Compressed package name.tar.gz tar -zxvf book.tar.gz Decompress the tar.gz package
tar -zcvf book.tar.gz book
tar -zxvf book.tar.gz
Copy the code

5.6 Shutdown and Restart Commands

5.6.1 shutdown

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

5.6.2 init

To turn it off

init 0
Copy the code

restart

init 6
Copy the code

5.6.3 logout

Log out

logout
Copy the code

5.7 Viewing The Login User Information

5.7.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

5.7.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)

5.7.3 last

  • View information about current and past login users

  • The default read

    /var/log/wtmp
    Copy the code

    file

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

5.7.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

5.8 File Viewing Commands

5.8.1 cat

  • The cat command is used to connect files and print to the standard output device.

  • cat [-AbeEnstTuv] [–help] [–version] fileName

  • parameter

    • -n or –number: indicates the number of lines starting with 1.

      cat -n textfile1
      Copy the code

5.8.2 more

  • Linux more commands are similar to cat, but are displayed page by page, making it easier for users to read page by page. The most basic command is to press the space key to go to the next page, press the B key to go back to the page, and search for strings (similar to vi). To describe the file in use, press H.
  • more fileName
more  testfile
Copy the code

5.8.3 head

  • Used to display an initial number of text blocks
head -5 readme.txt
Copy the code

5.8.4 tail

  • The tail command is used to view the contents of a file

  • A common parameter, -f, is used to view the log file that is being changed.

  • Tail [parameter] [file]

  • parameter

    • -f Reads in a loop

    • -n< Line number > Displays n lines at the end of the file

      tail -5 mail.txt
      tail -f access.log
      Copy the code

The second page 5.8.5

head -10 file | tail -5
Copy the code

6. File name of the hardware device

  • Whenever a hard disk is inserted, Linux automatically detects and assigns a name
  • A hard disk can be divided into multiple partitions, each of which has a system-assigned name
  • The name of the first SCSI hard disk issda, its first partition is calledsda1
  • The first virtualized disk isvda, its first partition is calledvda1
  • df(disk free)The command is used to display statistics on file system disk usage on Linux
df -h
Copy the code
hardware Device file name
IDE hard disk /dev/hd[a-d]
SCSI/SATA/USB hard drive /dev/sd[a-p]
Virtio disk /dev/vd[a-p]

6.1 IDE hard disk interface

6.2 SCSI Hard disk Interface

6.3 SATA disk ports

7. The partition

  • 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

8. The mount point

  • In order for these partitions to be accessible from a Linux system, they need to be mounted to the corresponding directory
  • In Linux, directories are calledThe mount point
  • The process of linking directories and partitions becomesmount
  • /Is the root directory and must be mounted on a partition to which all subdirectories are written by default
  • All subdirectories under the same level can have their own independent storage space
  • Required partitions
    • / root partition
    • Swap partition (Swap partition, virtual memory, usually two times of memory, do not exceed 2 gb)
  • Recommend partition
    • /boot (200M boot partition) An independent partition to prevent the system from being started when the partition is full

9.1 Mounting Example

  • /dev/sd2Mount the/Directory, that is to say to/Directory to write a file is to/dev/sd2Write files in the partition
  • /dev/sd1Mount the/bootDirectory, that is to say to/bootDirectory to write a file is to/dev/sd1Write files in the partition
  • /dev/sd3Mount the//homeDirectory, that is to say to//homeDirectory to write a file is to/dev/sd3Write files in the partition