Common script tools

Posted by pdunn on Fri, 01 Nov 2019 22:33:51 +0100

md5sum, command line view configuration

I. verifying file integrity with md5sum

Command options


 
1
2
3
4
5
6
md5sum
-b Read in file contents in binary mode
-t Read in file content in text mode
-c Based on generated md5 Value to verify the existing file
-w A warning message is given when the verification is not correct.
--status After verification, no error or correct prompt message will be generated, which can be judged by the return value of the command.

Use examples

  1. Generate file md5 value

    
     
    1
    2
    
    md5sum data
    0axxxxxxxxx data
    
  2. Using wildcards to md5 multiple files

    
     
    1
    2
    3
    
    md5sum *
    0axxxxxxx data
    14dxxxxxx data2
    
  3. md5 value redirection

    
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    # Single file redirection
    md5sum data > data.md5
    # Multiple file redirection
    md5sum * > d.md5
    cat d.md5
    0axxxxxxx data
    14xxxxxxx data2
    # Redirect append
    md5sum data3 >> d.md5
    
  4. md5 check

    
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    # Display verification information
    md5sum -c d.md5
    data: OK
    data2: OK
    data3: OK
    # Do not display the verification information, judge by the return value of the command
    md5sum -c --status d.md5
    echo $?
    0
    # Multiple file verification and grep are used to filter out the correct information
    md5sum -c d.md5 | grep -v OK
    

Special instructions

1) md5sum is to verify the content of the file, regardless of whether the file name is the same.

2) md5sum checks pixel by pixel, so the larger the file, the longer the check time

Reference resources

II. Terminal viewing computer information

Integration tool

  • screenfetch
  • neofetch
  • hwinfo –short

There are others. Reference resources.

command line

CPU


 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# View cpu statistics
lscpu

# View cpu model
cat /proc/cpuinfo | grep name | cut -f 2 -d : | uniq -c # Uniq-c counts the number of duplicate rows written on the left, and cut specifies the second column of fields for the separator with 
6  Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz ## 6-core i5-9600K cpu

# View the actual number of CPUs
cat /proc/cpuinfo | grep "physical id" | uniq -c 
6 physical id	: 0  ##A six core cpu

# View cpu bits
getconf LONG_BIT 
32 ## The current cpu is running in 32bit mode, but it does not mean that the cpu does not support 64bit

# Query whether the cpu supports 64bit
cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l 
6 ## The result is greater than 0, indicating that 64 bit computing is supported. lm means long mode, and lm means 64 bit.

Memory


 
1
2
3
4
free -m                             # View memory usage and swap usage
cat /proc/meminfo | grep MemTotal   # View total memory
cat /proc/meminfo | grep MemFree    # View the amount of free memory
dmidecode -t memory                 # View memory hardware information 

disk


 
1
2
3
4
5
6
7
8
9
lsblk                  # Intuitive view of hard disk and partition distribution
fdisk -l               # Detailed view of hard disk and partition distribution
df -h                  # Check the use of hard disk

mount | column -t      # View attached partition status
swapon -s              # View all swap partitions
hdparm -i /dev/hda     # View disk parameters (IDE devices only)
dmesg | grep IDE       # View IDE device detection status at startup
cat /proc/partitions   # Display hard disk partition information

system


 
1
2
3
4
5
6
7
8
9
10
lsb_release -a                   # View system version
uname -m && cat /etc/*release    # View basic system information
uname -a                         # View all information of the current operating system
cat /etc/issue                   # View current operating system release information
hostname                         # View computer name
lsmod                            # List loaded kernel modules
env                              # View environment variables
cat /proc/loadavg                # View system load
dmidecode | grep "Product Name"  # View machine model
uptime                           # View runtime load

Network card


 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# View network card hardware information
lspci | grep -i 'eth'                             
# View all network interfaces
ifconfig -a / ip link show                        
# View details of a network interface
ethtool enp2s0                                    
#Manually set the network card to adaptive, speed to 1000, full duplex mode
ethtool -s enp2s0 autoneg on speed 1000 duplex full

# Explain
#Modify the working mode of linux network card:
ethtool –r ethX                    ## Reset ethX network port to adaptive mode
ethtool –S ethX                    ## Query ethX network port receiving and contracting statistics
ethtool –s ethX [speed 10|100|1000]        ## Set network port rate 10/100/1000M
[duplex half|full]                ## Set network port half / full duplex
[autoneg on|off]                ## Set whether the network port is self negotiated

network


 
1
2
3
4
5
6
7
ifconfig               # View properties of all network interfaces
iptables -L            # View firewall settings
route -n               # View routing table
netstat -lntp          # View all listening ports
netstat -antp          # View all established connections
netstat -s             # View network statistics
dmesg | grep -i eth    # View network card information

user


 
1
2
3
4
5
6
w                         # view active user
id <User name>                # View specified user information
last                      # View user login log
cut -d: -f1 /etc/passwd   # View all users of the system
cut -d: -f1 /etc/group    # View all groups in the system
crontab -l                # View scheduled tasks for the current user

service


 
1
2
chkconfig --list              # List all system services
chkconfig --list | grep on    # List all started system services

program


 
1
2
3
4
5
6
7
8
dpkg -l                    # View all installed packages
dpkg -S opencv             # Search for related packages
dpkg -L libopencv-dev      # View package installation location
dpkg -s libopencv-dev      # View package information
dpkg --info xx.deb         # View packed deb file information
dpkg --contents xx.deb     # View packed deb content
dpkg -i xx.deb             # Install deb package
dpkg -P xx.deb             # Uninstall and delete configuration

Other


 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
lspci # View pci information, that is, information of all hardware slots on the motherboard - v details - t device tree
lspci
00:00.0 Host bridge: Intel Corporation 2nd Generation Core Processor Family DRAM Controller (rev 09) #Motherboard chip
00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09) #Graphics card
00:14.0 USB controller: Intel Corporation Panther Point USB xHCI Host Controller (rev 04) #usb controller
00:16.0 Communication controller: Intel Corporation Panther Point MEI Controller #1 (rev 04)
00:1a.0 USB controller: Intel Corporation Panther Point USB Enhanced Host Controller #2 (rev 04)
00:1b.0 Audio device: Intel Corporation Panther Point High Definition Audio Controller (rev 04) #sound card
00:1c.0 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 1 (rev c4) #pci slot
00:1c.2 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 3 (rev c4)
00:1c.3 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 4 (rev c4)
00:1d.0 USB controller: Intel Corporation Panther Point USB Enhanced Host Controller #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation Panther Point LPC Controller (rev 04)
00:1f.2 IDE interface: Intel Corporation Panther Point 4 port SATA Controller [IDE mode] (rev 04) #Hard disk interface
00:1f.3 SMBus: Intel Corporation Panther Point SMBus Controller (rev 04)
00:1f.5 IDE interface: Intel Corporation Panther Point 2 port SATA Controller [IDE mode] (rev 04) #Hard disk interface
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06) #Network card
03:00.0 PCI bridge: Integrated Technology Express, Inc. Device 8893 (rev 41)

lsusb # View all usb devices - v details - t device tree

dmidecode -t bios # View bios information

# dmidecode dump s the machine's DMI(Desktop Management Interface) information in a readable way. This information includes the hardware and BIOS, which can get the current configuration and the maximum configuration supported by the system, such as the maximum number of memory supported.
# If you want to see all the useful information
dmidecode -q
dmidecode -t [bios,  system,  baseboard,  chassis,  processor,  memory, cache,  connector,  slot] # View corresponding hardware information

Reference resources

Topics: network Linux firewall Ubuntu