[命令] GNOME 命令 gnome-terminal (打开新的命令行终端)

案例一:打开新的命令行终端,在 1 个新的窗口上运行

# gnome-terminal

案例二:打开新的命令行终端,并自定义窗口的大小和位置,在 1 个新的窗口上运行

# gnome-terminal --geometry=120*80+20+10

(补充:这里以打开新的命令行终端,并将终端窗口设置为宽 120,高 80,左偏移量 20,上偏移量 80 为例)

案例三:最大化打开新的命令行终端,在 1 个新的窗口上运行

# gnome-terminal --maximize

案例四:全屏话化打开新的命令行终端,在 1 个新的窗口上运行

# gnome-terminal --full-screen

案例五:打开新的命令行终端,并设置标题,在 1 个新的窗口上运行

# gnome-terminal --title="Eternal Center"

(补充:这里以打开新的命令行终端,并将终端窗口名命名为 Eternal Center 为例)

案例六:同时打开多个新的命令行终端,在 1 个新的窗口上运行

6.1 同时打开 2 个新的命令行终端,在新的窗口上运行 (每 1 个窗口 1 个新的命令行终端)

# gnome-terminal --window --window

6.2 同时打开 4 个新的命令行终端,在新的窗口上运行 (每 1 个窗口 2 个新的命令行终端)

# gnome-terminal --window --tab --window --tab

[工具] Shell 显示系统常用信息

介绍

基本信息

作者:朱明宇
名称:显示系统常用信息
作用:显示系统常用信息

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本分割线里的变量

1. times=5 #显示系统常用信息的次数
2. sleeptime=0.3 #大部分行与行之间显示的间隔时间

注意

1. 需要安装 sysstat 软件
2. 执行此脚本的用户能够使用 sudo ip a s 命令
3. 执行此脚本的用户能够使用 sudo ss -ntulap 命令
4. 搭建了 KVM 虚拟化平台后执行此脚本的用户能够使用 sudo virsh list 命令后才能实现

脚本

#!/bin/bash

####################### Separator ########################
times=5
sleeptime=0.3
####################### Separator ########################

nowtime=1

while (( nowtime <= times))
do
        echo -e "Start Monitoring: \c"
	for i in {1..94}
	do
	        echo -e "#\c"
		sleep 0.01
        done
	echo

	sleep $sleeptime
        host=`hostname`
        echo -e "Name:\t\t\t\t\t\t\t \033[1m$host\033[0m"

        ip=`sudo ip a s | awk '/[1-2]?[0-9]{0,2}\.[1-2]?[0-9]{0,2}/&&!/127.0.0.1/{print $2}' | awk -F/ '{print $1}'`
	for iip in $(echo $ip)
        do
		sleep $sleeptime
                echo -e "IP Address:\t\t\t\t\t\t \033[1m$iip\033[0m"
        done

        sleep $sleeptime

        cpu=`top -bn 1 | awk -F',' '/^%Cpu/{print $4 }' | awk '{print $1}' | awk '{print 100-$1}'`
        echo -e "CPU Usage (Total):\t\t\t\t\t \033[1m$cpu%\033[0m"

        sleep $sleeptime

        mem=`free | grep Mem | awk '{print $3/$2 * 100.0}' | egrep -o "[1]?[0-9]{0,2}\.[0-9]"`
        echo -e "Memory Usage (Total):\t\t\t\t\t \033[1m$mem%\033[0m"

	directory=`df -h | grep -v run | grep -v boot | awk '$1~/\/dev/{print $6}'`
        for idirectory in `echo $directory`
        do
                sleep $sleeptime
                directoryusage=`df -h | grep -v run | grep -v boot | awk '$1~/\/dev/{print}' | grep $idirectory$ | awk '{print $5}'`
		if [ $idirectory == / -o $idirectory == /sda -o $idirectory == /sdb  ];then
                        echo -e "Directory Usage ($idirectory):\t\t\t\t\t \033[1m$directoryusage\033[0m"
	        else
                        echo -e "Directory Usage ($idirectory):\t\t\t\t \033[1m$directoryusage\033[0m"
		fi
        done

	sudo -l | grep 'virsh list' &> /dev/null
        if [ $? -eq 0 ];then
	        sleep $sleeptime
	        virtual=`sudo virsh list | egrep [0-9] | wc -l`
	        echo -e "Number of Virtual Machines (Total):\t\t\t \033[1m$virtual\033[0m"
        fi

        sleep $sleeptime

        user=`who | wc -l`
        echo -e "Number of User Logins (Total):\t\t\t\t \033[1m$user\033[0m"

        soft=`rpm -qa | wc -l`
        echo -e "Number of Softwares (Total):\t\t\t\t \033[1m$soft\033[0m"

        sleep $sleeptime

        port=`sudo ss -ntulap | wc -l`
        echo -e "Number of Open Ports (Total):\t\t\t\t \033[1m$port\033[0m"

        which sar &> /dev/null
        if [ $? -eq 0 ];then
                networkcard=`ifconfig | awk -F: '/flags/&&!/lo/{print $1}'`
                for inetworkcard in `echo $networkcard`
                do
                        networkread="`sar -n DEV 1 1 | grep $inetworkcard | awk '/[0-9][0-9]:[0-9][0-9]/{print $3/1000}'` m/s"
                        networkwrite="`sar -n DEV 1 1 | grep $inetworkcard | awk '/[0-9][0-9]:[0-9][0-9]/{print $4/1000}'` m/s"
			echo $inetworkcard | grep eth &> /dev/null
			if [ $?  -ne 0 ];then
	                echo -e "Network Card IO ($inetworkcard):\t\t\t\t \033[1m$networkread\033[0m (Read)\t\033[1m$networkwrite\033[0m (Write)"
		        else
	                echo -e "Network Card IO ($inetworkcard):\t\t\t\t\t \033[1m$networkread\033[0m (Read)\t\033[1m$networkwrite\033[0m (Write)"
			fi
                done
        fi

        which iostat &> /dev/null
        if [ $? -eq 0 ];then
	        disk=`iostat -d -k 1 1 | awk '!/^$/&&!/Device/&&!/Linux/{print $1}'`
                for idisk in `echo $disk`
	        do
			sleep $sleeptime
		        diskread="`iostat -d -k 1 1 | grep $idisk |  awk '{print $3/1000}'` m/s"
		        diskwrite="`iostat -d -k 1 1 | grep $idisk |  awk '{print $4/1000}'` m/s"
			echo $idisk | grep 'nvme' &> /dev/null
			if [ $? -eq 0 ];then
		                echo -e "Disk IO (/dev/$idisk):\t\t\t\t\t \033[1m$diskread\033[0m (Read)\t\033[1m$diskwrite\033[0m (Write)"
		        else
		                echo -e "Disk IO (/dev/$idisk):\t\t\t\t\t \033[1m$diskread\033[0m (Read)\t\033[1m$diskwrite\033[0m (Write)"
			fi
	        done

        fi

        echo -e "Complete Monitoring: \c"
        for i in {1..91}
        do
                echo -e "#\c"
                sleep 0.01
        done
        echo
        sleep $sleeptime

        let nowtime++
done

        echo -e "Terminal Monitoring: \c"
        for i in {1..91}
        do
                echo -e "#\c"
                sleep 0.01
        done

exit

[步骤] Linux 自动退出时间的设置

步骤一:确认目前正在使用的解释器是 /bin/bash

# echo $SHELL
/bin/bash

步骤二:临时设置多久以后会自动退出

# export TMOUT=30

(补充:这里以设置 30 秒后会自动退出为例)

步骤三:永久设置多久以后会自动退出

3.1 修改 /etc/bash.bashrc 配置文件

# vim /etc/bash.bashrc

添加以下内容:

......
TMOUT=900 ; export TMOUT

3.2 修改 /etc/profile 配置文件

# vim /etc/profile

添加以下内容:

......
TMOUT=900 ; export TMOUT

[命令] Linux 命令 tcpdump (网络抓包)

内容一:tcpdump 命令格式

# tcpdump <option> <proto> <dir> <type>

内容二:tcpdump 命令选项 (option)

1) -A use ASCII print all data, it is convenient for read website date.
2) -c <number>, number of packet captures
3) -C <file size>,size of file
4) -e, display data link layer
5) -G <second>, create a new file after these seconds 
6) -l, send the output to next command, example: tcpdump -i eth0 -s0 | grep 'Server:'
7) -n, do not resolve domain only display IP address
8) -nn, do not resolve domain and port only display IP address
9) -i <interface>, such as internet card and can use: -i any
10) -p, only display the data which point it self
11) -r <file>, read data from file 
12) -s <snaplen>, size of length of the network package and can use: -s 0 to ulimite the length, the default value is 96B
13) -v , display detail
14) -vv, display detail more than -v
15) -vvv, display detail more than -vv
16) -w <file>, write the output result into a file
17) -W <number>, how many files will output result into

内容三:tcpdump 命令协议 (proto)

1) tcp or proto 6
2) udp or proto 17
3) icmp, example: proto \\icmp is icmp
4) ip
5) ip6
6) arp
7) rarp
8) ether
9) wlan

内容四:tcpdump 命令方向 (dir)

1) src
2) dst

内容五:tcpdump 命令种类 (type)

1) host <IP address>
2) net <network segment>, example: 10 is 10.x.x.x/8 , 192.168.0 is 192.168.0.0/24
3) port <port>
4) portrange <port range>

内容六:tcpdump 命令逻辑

1) and or &&
2) or or ||
3) not or !

内容七:tcpdump 命令的使用案例

7.1 显示发送到某个 IP 地址的某个端口的网络数据包

# tcpdump -i any dst 192.168.0.1 and udp port 514

(补充:这里以显示发送到 IP 地址 192.168.0.1 的 UDP 514 端口为例,如果有这类网络数据包的话则详细信息会在命令输出后显示出来)

7.2 显示从某个 IP 地址发送来的网络数据包

# tcpdump -vv src host 192.168.0.1

(补充:这里以显示从 IP 地址 192.168.0.1 发送来的网络数据包为例,如果有这类网络数据包的话则详细信息会在命令输出后显示出来)

7.3 将所有抓到的网络数据包导入到某个文件里

# tcpdump -i any -w /tmp/telnet.cap

(补充:这里以将所有抓到的数据包导出到文件 /tmp/telnet.cap 为例)

7.4 将某个网卡抓到的网络数据包导入到某个文件里

# tcpdump -i eth0 -s 0 -w /tmp/$(hostname)-$(date +"%Y-%m-%d-%H-%M-%S").pcap host 192.168.1.1 or host 192.168.1.2

(补充:这里以将网卡 eth0 网卡上抓到的来源或目的是 192.168.1.1 或 192.168.1.2 的数据包导出到文件 /tmp/$(hostname)-$(date +”%Y-%m-%d-%H-%M-%S”).pcap 为例)