Linux common command record

preface

Our applications are generally deployed on Linux, so we have to learn linux commands to solve problems. According to experience, commonly used commands are basically used again before forgetting, so it's natural to remember. Occasionally used commands still have an impression when they are used next time. They can be remembered after several times. More importantly, the command line still has rules to follow. Now record the commonly used command line for future reading and deepening your impression.

Log related commands

There seems to be a problem with folding grammar, and the answer is put at the back

1. View log size

2. View the log immediately after

3. Query the log after 1000 rows

4. Query the first 10 lines of logs in the log file

5. Query all logs except the last 10 lines of the log file

6. Command to view logs of two time periods (Note: if the time does not exist, it will become invalid, and the slash needs to be escaped)

7. Transfer the file to the idle server

answer
1.ls -lh text.log
2.tail -f text.log
3.tail -n -1000 text.log
4.head -n 10 text.log
5.head -n -10 text.log
6.sed -n '/2021-06-04 14:05/,/2021-06-04 14:06/p' test.log
7.scp test.log root@192.168.1.100:/home/

Add file permissions

chmod u+x *.sh

1. u On behalf of the owner;
2. + Indicates adding permissions;
3. x Executive authority of the representative;
4. r Delegate read permissions
5. w Represents write permission
6. *.sh Indicates all in the current directory .sh File.

Process network port related

ss performs better than netstat

View tcp status

  • netstat -napt

View service port

  • netstat -anlp | grep process number

Query service process

  • ps -ef | grep service name

View network configuration

  • ip -s addr show dev eth0

socket information viewing

  • ss -nlp

    • -n means that the ip and port are displayed in numerical form instead of the name
    • -l indicates that only the socket with LISTEN status is displayed
    • -p means to display process information
  • ss -ltnp

    • -l indicates that only the socket with LISTEN status is displayed
    • -t indicates that only tcp connections are displayed
    • -n means that the ip and port are displayed in numerical form instead of the name
    • -p means to display process information

Protocol stack statistics

  • ss -s

Network throughput and PPS viewing

  • sar -n DEV, display network port statistics

    IFACE: LAN Interface
    rxpck/s: Packets received per second
    txpck/s: Packets sent per second
    rxbyt/s: Bytes received per second
    txbyt/s: Bytes sent per second
    rxcmp/s: Compressed packets received per second
    txcmp/s: Compressed packets sent per second
    rxmcst/s: Multicast packets received per second
  • sar -n EDEV to display statistics about network errors

    IFACE: LAN Interface
    rxerr/s: Bad packets received per second
    txerr/s: Bad packets sent per second
    coll/s: Conflicts per second
    rxdrop/s: The number of received packets dropped per second because the buffer is full
    txdrop/s: The number of sent packets dropped per second because the buffer is full
    txcarr/s: Number of carrier errors per second when sending packets
    rxfram/s: The number of frame alignment errors received per second
    rxfifo/s: Packets received per second FIFO Number of overspeed errors
    txfifo/s: Packets sent per second FIFO Number of overspeed errors
  • sar -n TCP to display TCP statistics

Bandwidth view

  • ethtool eth0 | grep Speed

Test this machine with www.baidu.com Com connectivity and latency

  • ping www.baidu.com -c 5

File mount

  1. The NFS server configuration method of linux system is as follows

    (1) Modify / etc/exports to add a shared directory

    /export/home/sunky 10.140.133.23(rw) 
    /export/home/sunky1 *(rw) 
    /export/home/sunky2 linux-client(rw)

    Note: Sunky, sunky1 and sunky2 in the directory: / export/home / are the directories to be shared, 10.140.133.23, *
    linux client is the IP address or hostname that is allowed to attach this shared linux client. If you want to use the host name, the linux client must be on the server host
    /Add the Linux client host ip definition in the / etc/hosts file. The format is as follows:

    10.140.133.23 linux-client

    (2) Start and stop services for NFS

    /etc/rc.d/init.d/portmap start (stay REDHAT in PORTMAP Is started by default) 
    /etc/rc.d/init.d/nfs start start-up NFS service 
    /etc/rc.d/init.d/nfs stop stop it NFS service

    Note: if you modify the / etc/export file to add a new share, you should first stop service for NFS and then start service for NFS to make the newly added share work.
    The same effect can be achieved by using the command exportfs -rv.

  2. linux client mounts NFS shares of other linux systems or UNIX systems

    # mkdir –p /mnt/nfs

    Note: create a directory to use as mount point

    #mount -t nfs -o rw 10.140.133.9:/export/home/sunky /mnt/nfs

    Note: Here we assume that 10.140.133.9 is the host IP address of the NFS server. Of course, the host name can also be used here, but the server IP definition must be added in the local / etc/hosts file/ export/home/sunky is the directory shared by the server.
    In this way, you can access files shared by other linux systems or UNIX systems through / mnt/nfs on the linux client.
    The above operations are in redhat as server 3 and Redflag server4 1. suse server 9 and Solaris 7, Solaris 8 and Solaris 9 for x86 & SPARC environment passed the test.

    View disk usage and mount points

  • df -h

    Filesystem Refers to the hardware device files on the system
    Size Refers to the total size of the hard disk or partition.
    Used Indicates the size that has been used
    Avail Indicates the size that can be used.
    Use%Indicates the percentage of space that has been used.
    mounted on Indicates the directory where the hard disk is mounted.

    Use of top command

    top

    top -       Current system time
    up       How long has the system been powered on
    user      Current number of users
    load average cpu Average load, the three values are, 1 minute, 5 minutes and 15 minutes respectively
    Tasks    Current system processes, total: Total processes, running: Number of running processes, sleeping: Number of sleep processes, stopped: Number of processes stopped, zombie: Number of zombie processes
    %Cpu(s) cpu Utilization rate, us: User use cpu 100 percent, sy: System kernel usage cpu 100 percent, id: remainder cpu 100%
    Mem     Memory usage information, total: Total memory size, free: Free memory, used: Memory used, buff/cache: Cache memory size
    Swap    Virtual memory information
    PID     process id
    USER     Process owner
    PR       priority
    NI       nice A negative value indicates high priority and a positive value indicates low priority
    VIRT       The total amount of virtual memory used by the process
    RES       The amount of physical memory used by the process
    SHR       Shared memory size
    S        Process status, D: An uninterrupted sleep state, R: function, S: Sleep, T: track/stop it, Z: Zombie process
    %CPU      Used by the process CPU Occupancy percentage
    %MEM      Percentage of physical memory used by the process
    TIME+      Used by the process CPU Total time
    COMMAND   Command name

    View the threads in the process: top -Hp pid

    find command

    find + directory + condition + condition value

    stay/home Find all below to .txt End file: find /home -name "*.txt" 
     -type Is a type parameter
              f     Representation file
              d    Represents a directory
              c    Represents a character device
              b    Represents a block device
              s    Represents a socket
              l     Represents a link
     lookup/mnt Subdirectories under: find /mnt -type d

    Configure environment variables

    In / etc/profile or user directory Configure environment variables in profile file

     export GOROOT=/usr/local/go
     export GOPATH=/home/william/goProject 
     export GOBIN=$GOPATH/bin
     export PATH=$PATH:$GOROOT/bin
     export PATH=$PATH:$GOPATH/bin

Keywords: Linux

Added by kikki on Wed, 05 Jan 2022 08:40:57 +0200