0 1
Linux Basics



1. A brief introduction to the Linux system

Linux is a free-to-use, multi-user, multi-tasking, multi-threading and multi-core CPU operating system; many medium, large and even huge projects are using Linux.


The Linux distribution is simply a package of Linux and application software.  At present, the more well-known distributions on the market are: Ubuntu, RedHat, CentOS (community enterprise operating system) and so on.

Comparison of Windows and Linux

Windows

linux

TOLL

TOLL

open source free

software resources

There are abundant software resources, but most of them may need to purchase copyright

Most of the software can be freely obtained, and there are fewer choices of software with the same function

Technical Support

Mainly graphical interface

Mainly character mode, command line interface

safety

Large trees attract the wind and are more prone to being attacked

There are many released versions, and it is difficult to focus on attacks


2. Why learn Linux?

The project server is generally a Linux system, responsible for building and maintaining the test environment, and responsible for tracking and locating bugs.


Image



0 2
Linux Beginner and Intermediate Commands


  • Remote operation of Linux system through xshell and xftp

  • What is xshell and xftp?


xshell is a client software, we use it on the local Windows to connect to the Linux system ( server), and operate Linux through the command line interface it provides .

  • xftp is a file transfer software that can transfer files from local Windows to server Linux systems

  • If the xshell connection page displays garbled characters, you need to change the default language to unicode (utf-8), click the globe icon in the menu bar to change


0 1
Linux primary command



  • System management related commands

  • Login basic information

  • Current login username

  • # admin user prompt

  • $ normal user prompt

  • CPU name

  • Current directory

  • hostname: View the hostname

  • who: query the user logged in to the system

  • whoami: confirm your identity

  • history: View the history of commands run by the current user

  • ifconfig: command to display or set network devices, we can view the IP address of the server through this command

  • ping: ping is a command under Windows, Unix and Linux systems. Ping also belongs to a communication protocol, which is part of the TCP/IP protocol. Use the "ping" command to check if the network is connected


Linux system directory structure

  • The Linux file system adopts a hierarchical tree-like directory structure,  in which the top level is the root main directory, and the bottom level is various subdirectories and files.

  • It is very important to understand the relevant linux file directories under the root directory:

    Image


Directory manipulation commands

  • pwd  command displays the current path

  • cd  command to change directory

    Usage:  cd directory path

    cd ./ current directory

    cd .. switch to the parent directory

    cd / to change to the root directory

    cd ~ (or just cd ) to switch to the current user's home directory (the folder named after the username under home) /root directory

    The difference between cd /opt à cd bin

  • mkdir   create directory

    The difference between mkdir directory name –p plus p and no p

  • rmdir   removes empty directories

    Usage:   rmdir directory name

    Also available: rm -rf dirname/filename


0 2
Linux Intermediate Commands



File operation command 01

In the Linux system, almost all contents including documents, commands, devices and directories are organized in the form of files and managed by files;


Common file commands are:

  • touch   to create a new file usage touch fanmao.txt

  • vi  is a commonly used and powerful text editor under linux

    Press the keyboard i to enter the editing state

    Exit the editing state and press the ESC key. Exit method

    Quit without saving: :q! force quit

    Save and exit: :wq


When entering the file:

  • Enter /fanmao: search for fanmao from the beginning of the cursor to the end of the file

  • Enter ?fanmao: search for fanmao from the cursor start to the beginning of the file

  • Enter: set nu, display the number of lines in each line

    Press the keyboard G, you can directly navigate to the end

     Note:  Keyboard input is all English input method for input


File operation command 02

  • ls to  view directories and files

    Usage: ls [options] path (if there is no path, the contents of the current directory will be displayed)

  • -a  show all files hide files

  • -l  show file attributes

  • cp  copy command

    Usage: cp [options] filename or directory target address

  • -R  copy directory and all directories and files under the directory directory (folder)

  • cp a.txt b.txt Copy the a file and rename it as the b file (directory name)

  • mv  move command

    Usage: mv filename or directory target directory

  • mv a.txt ../ move a file to the parent directory (moving a file to another directory without renaming)

  • mv a.txt ../b.txt move a file to the previous level and rename it to b file (move a file to another directory and rename it)


File Operation Command 03

  • rm   removes files and directories

  • -f   force delete

  • -r   delete directory

    Commonly used: rm -rf file or directory

  • find  find files

    Usage: find [path] [options]

    Common options are:

    ① find . –name *.log Find files ending with .log in the current directory

    ② find / -name log Find the directory named by log in the root directory

  • grep finds a character (string) in the specified file and prints the line:

    filter, often with the pipe symbol |

    Usage:  ① grep string filename

    ② grep band file Find the band string in the file file


File Operation Command 04

  • cat  display text file content

    Usage: cat filename cat filename

  • head  to see the first few lines

    Usage: head –n 5 filename

  • tail  starts writing the file to standard output from the specified point, use the -f option of the tail command to easily view the log file that is changing

    ① tail –n 5 View the last few lines of the file name

    ② tail –f error.log is constantly refreshed to see the latest content


System resource query command

  • ps  view process (dynamic)

  • -ef   show all running processes and show the command to start the process

  • Uid   user ID, PID: process id, PPID: parent process, C: process cpu usage, Stime: time since the process started, TTY: terminal number, CMD: command name and parameters

  • netstat   View network status (short for net status)

  • netstat –apn  view all ports

  • an , arrange the output in a certain order

  • p , which shows which process is calling

think:

How to write if you want to filter a port or a process?

Replenish

kill:  kill the process (kill -9 process number forcibly kills the process)


pipe command

  • The pipe uses the "|" symbol, and establishes a pipeline between commands, taking the output of the previous command as the input of the following command

    For example: ll | grep abc: The command in front of the pipeline displays the files in the current directory, and then finds the file or directory containing the abc string from the listed file names


Common situation of work:  kill process (such as kill tomcat process)

  • Find the process by the process name , and then kill the process

  • Find the tomcat process by command | : ps –ef | grep tomcat (ps –ef is to find all running processes, and find all processes that contain the “tomcat” string through the pipe character, which is the tomcat process), for example: 5541

    To kill this process, kill -9 process id (kill -9 5541)

  • Find the process by port , then kill the process

  • Find the process number occupying this port through the command : netstat –apn|grep 8080 Check the process according to 8080, if: 5541

    Kill process: kill -9 pid (kill -9 5541)

Supplementary Knowledge Points - Beginners' Notes

  • Error prompt:  command not found, command not found, the first reaction to see this command is to check whether the command is written incorrectly

  • Copy directory error in Linux cp :  omitting directory—this error generally occurs, it is the directory under the directory, and cannot be copied directly -R traverses all contents

PS:

  • Ctrl + c to end the currently running program

  • Tab key use, auto-association, quick completion

  • Arrow keys "up", "down", search history commands, previous, next



0 3
Linux Advanced Commands


0 1
Empower command chmod‍



The Linux system is a typical multi-user system. Different users are in different positions and have different permissions. In order to protect the security of the system, the Linux system has different permissions for different users to access the same file (including directory files). Provisions. In Linux, we can use the ll or ls -l command to display the attributes of a file and the user and group to which the file belongs;


like:

Image

Image 

chmod syntax:  chmod [-R] 753 (number) file or directory

    Read (r): 4 Write (w): 2 Execute (x): 1

    chmod –R 754 fanmao07

Test environment:   chmod –R 777 fanmao07


0 2
Compress and decompress commands



Unzip tar.gz

  • Compress the file into .tar.gz/ .tar format with the tar command,  use -z to invoke gzip

    For example:  compress the test folder into test.tar.gz

  • tar –czvf test.tar.gz test

    The tar command is also used to decompress the .tar.gz/.tar format file

    For example:  extract test.tar.gz to get the test folder

    tar –xzvf test.tar.gz


Detailed explanation of command parameters:

  • -c   build archive/compress

  • -x   unarchive/decompress

  • -z   Compressed files with gzip attribute

  • -v   show all processes

  • -f   use the file name, the required item, is the last parameter, followed by the file name


unzip the zip

  • Compress the file into .zip format with the zip command

    For example:  compress the test folder into test.zip, you must include r to compress the file, otherwise an empty folder will be generated

    zip –r test.zip test

  • Unzip the compressed file in .zip format using the unzip command

    For example:  unzip the test.zip folder

    unzip test.zip 


0 3
switch firewall command



  • Effective immediately, invalid after restart

    Start:  service iptables start

    shutdown:  service iptables stop 


0 4
Restart, Shutdown, Logout Commands



  • Reboot command: reboot

    Others: shutdown –r now

  • Shutdown command: halt

    Other: shutdown -h now

    poweroff

  • logout: logout 


Supplementary content: (common network knowledge points)

  • firewall concept

    The so-called "firewall" refers to a method that separates the internal network from the public access network (such as the Internet).  It is actually an isolation technology to protect the internal network from the intrusion of illegal users . Network security system with external network. An information security protection system that allows or restricts the transmission of data through specific rules

  • Firewall settings for online environments

  • Operation and maintenance/development management and maintenance

  • Firewall settings for the test environment

  • If you test the intranet, you must set it and close it directly

If you want to know more, you can pay attention to our public account or scan the QR code below to add us to understand~~

Image