Basic knowledge of Linux - practical operation of Linux (yum, date, time zone, fixed IP, ping, wget, curl, nmap, nestat, process management, host status monitoring, disk information monitoring, network status monitoring, upload, download)

Linux practical operation

  • Force stop: ctrl+c
  • Cancel the current command: ctrl+c
  • Log out of the current account: ctrl+d
  • Exit the exclusive page of some specific programs: ctrl+d
  • View the history commands entered: history
  • Automatically execute the last command matching the prefix: ! command prefix
  • Match historical commands according to the input content: first press ctrl+r, enter the content, and seek a match
  • Jump to the beginning of the command: ctrl+a
  • Jump to the end of the command: ctrl+e
  • Jump a word to the left: ctrl+keyboard left key
  • Jump one word to the right: ctrl+keyboard right key
  • Empty terminal content: ctrl+L or clear

It is worth mentioning that CentOS and Ubuntu use different package managers, the former is yum and the latter is apt

Install software using yum

Yum is an RPM package software manager, which is used to automatically install and configure Linux software, and can automatically resolve dependency issues.

Yum requires root privileges and networking, you can use su to switch to root, or use sudo to elevate privileges

Syntax: yum [-y] [install or remove or search] software name

  • -y, automatic confirmation, no need to manually confirm the installation or uninstallation process
  • install install
  • remove uninstall
  • search search

For CentOS, his software installation package is .rpm

Install software using apt

Syntax: yum [-y] [install or remove or search] software name

For Ubuntu, his software installation package is .deb

systemctl command

Used to control the startup and shutdown of software [software that can be controlled and managed, generally also called services]

[Such as networkmanage primary network service, network secondary network service, firewalld firewall service...]

Syntax: systemctl start | stop | restart | disable | enable | status service name

  • start, start
  • stop, stop
  • status, view the status
  • disable, turn off autostart
  • enable, turn on the boot automatically
  • restart, restart

Some software will not be manually integrated into systemctl after installation, we can add it manually.

create soft link

Function: Create file, folder soft link (shortcut)

Syntax: ln -s parameter 1 parameter 2

  • Parameter 1: The file or folder to be linked
  • Parameter 2: The place to link to (the name and storage location of the shortcut)
  • -s is to create a soft link

date and time zone

Syntax: date [-d] [+format string]

  • -d Display the date according to the given string, generally used for date calculation
  • Format string: Control the displayed date format through specific string tags
    • %Y year (2023)
    • %y Last two digits of the year (00 .99)
    • %m month (01.12)
    • %d days (01.31)
    • %H hours (00 .23)
    • %M minutes (00 .59)
    • %S seconds (00 .60)
    • %s The number of seconds since 1970-01-01 00:00:00 UTC

[Case: date "+%Y-%m-%d %H:%M:%S", which results in: 2023-04-03 05:50:36]

The time stamps supported by -d are: year, month, day, hour, minute, second

[Case: date -d "+10 day" gives the current date +10 days later]

Time zone

Under root authority, modify the time zone to China time zone (East Eighth District), or use sudo to escalate the rights

sudo rm -f /etc/localtime

sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ntp program

Use the ntp program to automatically calibrate the system time, and regularly help me connect to the Internet to determine the specific time
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd
can also be manually calibrated (root authority), ntpdate -u ntp.aliyuncom

ifconfig

View the ip address of the machine

If you cannot use this command, you can install the program, yum -y install net-tools

hostname

View the hostname of the Linux system

Modify the host name (under root authority or sudo privilege escalation): hostnamectl set-hostname xxx

Configure a fixed IP address for Linux in the VM

Because the IP address of the Linux system in our virtual machine is obtained through DHCP (Dynamic Host Configuration Protocol), if the IP is not fixed, the IP must be obtained again every time the device is restarted, resulting in frequent changes in the IP address.

  1. Configure the IP address gateway and network segment in the VM
    1. Edit -> Virtual Network Editor -> You can modify the subnet and mask in VMnet8
    2. Then click NAT settings and set the gateway IP
  2. Modify the configuration file in the Linux system and fix the IP
    1. Use vim editor to edit files, vim /etc/sysconfig/network-scripts/ifcfg-ens33
    2. Change dhcp in BOOTPROTO="dhcp" to static
    3. Add the following content (serial number is not required)
      1. IPADDR=“192.168.88.130”
      2. NETMASK=“255.255.255.0”
      3. GATEWAY=“192.168.88.2”
      4. DNS1=“192.168.88.2”
  3. Restart the network card to systemctl restart network

ping command

Test whether the network is connected

Syntax: ping [-c num] parameters

  • -c num sets the number of checks, if the -c option is not written, it will be checked infinitely
  • The parameter is an IP address or a hostname

wget command

A non-interactive file downloader that can download network files from the command line

Syntax: wget [-b] url

  • -b is optional, background download, the file is downloaded to the user's home directory, and the log will be written to the wget-log file in the current working directory
  • url, download link

curl command

curl can send http network requests for downloading files, obtaining information, etc.

Syntax: curl [-O] url

  • -O user downloads the file, when the url is a download link, you can use this option to save the file
  • url, the network address to initiate the request

View the port exposed by an IP

You need to use the nmap command, first install nmap: yum -y install nmap

Syntax: nmap needs to view the IP address

View local port usage

You can use the netstat command, combined with pipe symbols and filter instructions , to check the occupancy of the specified port

Install netstat first: yum -y install net-tools

Syntax 1: nestat -anp【View all port port conditions】

Syntax 2: nestat -anp | grep port number【Check the occupancy of the specified port】

process management

Programs are managed by the operating system. In order to manage running programs, each program is registered as a process in the system by the operating system when it is running. Assign a unique process ID to each process.

view progress

Syntax: ps [-e -f]

  • -e shows all processes
  • -f display information in formatted form

[Usually: ps -ef can list all information of all processes]

Information displayed:

  • UID: the ID of the user to which the process belongs
  • PID: Process ID of the process
  • PPID: The parent ID of the process (other processes that started this process)
  • C: CPU usage (percentage)
  • TTY: The serial number of the terminal that started this process. (? indicates non-terminal startup)
  • TIME: CPU time occupied by the process
  • CMD: the name corresponding to the process or the startup path or the startup command

close process

Syntax: kill [-9] process ID

  • -9, optional, means force close

Host status monitoring

View system resources

You can use the top command to view the cpu and memory usage (similar to the Windows task manager), which is refreshed every 5 seconds by default

Press q or ctrl+c to exit

The meaning of some fields:
insert image description here
insert image description hereinsert image description here
insert image description here

Disk information monitoring

1. Use the df command to view disk usage

Syntax: df [-h]

  • -h, optional, display in more human-friendly units

2. Use iostat to view cpu and disk related information

Syntax: iostat [-x] [num1] [num2]

  • -x show more information
  • num1 refresh interval
  • num2 refresh times

Analysis of some fields: tps device transmission times per second, kB_read/s per second read rate, kB_wrtns/s per second write rate, kB_read total reads, kB_wrtn total writes, %util disk utilization

Network Status Monitoring

You can use the sar command to view the relevant statistics of the network

Syntax: sar -n DEV num1 num2

  • -n, view the network, DEV means view the network interface
  • num1 refresh interval
  • num2 number of views (unlimited if not filled in)
    insert image description here
    upload and download (for FinalShell)

File transfer using rz, sz commands

These two commands must be installed first, yum -y install lrzsz

Upload: Enter rz directly

Download: sz file to download

Guess you like

Origin blog.csdn.net/qq_41954181/article/details/129957651