[命令] Linux 命令 tput 的使用 (设置光标和文本的属性)

正文:

内容一:tput 的简单使用案例

1.1 使用案例一:清屏

# tput clear

1.2 显示当前命令行宽度

# tput cols

内容二:tput 的光标设置案例

2.1 使用案例二:让光标可见和不可见

2.1.1 让光标不可见
# tput civis
2.1.2 让光标可见
# tput cnorm

2.2 保存当前光标的位置

# tput sc

2.3 将光标条跳转到第某行的第某列

# tput cup 20 30

(补充:这里以将光标跳转到第 20 行的第 30 列为例)

2.4 显示输出结果

# tput rc

内容三:tput 的颜色设置案例

3.1 tput 的颜色设置选项

1) 0,黑色
2) 1,蓝色
3) 2,绿色
4) 3,青色
5) 4,红色
6) 5,洋红色
7) 6,黄色
8) 7,白色

3.2 tput 的颜色设置案例

3.2.1 设置字体颜色
# tput setaf 1

(补充:这里以把字体设置成蓝色为例)

3.2.2 设置背景颜色
# tput setab 4

(补充:这里以把背景设置成红色为例)

3.3.3 同时设置字体的颜色和背景的颜色
# tput setaf setab

(补充:这里以把字体设置成蓝色把背景设置成红色为例)

内容四:tput 的字体格式设置案例

4.1 设置字体加粗

# tput bold

4.2 设置字体有下划线

# tput underline

内容五:tput 的组合设置案例

5.1 在位置第某行的第某列输出信息

# tput sc ; tput cup 23 45 ; echo “Output this location is 23/45” ; tput rc


补充:
1) 这里的 tput sc 是保存当前的光标位置
2) 这里的 tput cup 23 45 是将光标移动到第 23 行的第 45 列
3) 这里的 echo “Output this location is 23/45” 是输出内容 “Output this location is 23/45”
4) 这里的 tput rc 是将光标回到刚刚保存的光标位置
5)这里以在第 23 行的第 45 列输出信息 “Output this location is 23/45” 为例

参考文献:

tput

[内容] Linux 版本的查看

内容一:Linux 版本整体信息的查看

如果是 openSUSE & SLES & Rocky Linux & RHEL:

# cat /etc/*release*

如果是 Rocky Linux & RHEL:

# cat /etc/redhat-release

内容二:Linux 版本某项具体信息的查看

2.1 查看此系统属于哪种 Linux

# lsb_release -i -s 2> /dev/null

2.2 查看此系统的本版

# lsb_release -r -s 2> /dev/null

2.3 查看此系统的内核版本

# uname -r 2> /dev/null

[命令] Linux 命令 nestat (显示本地端口,以及其 PID 信息等)

案例一:显示所有端口

$ netstat -ntulap
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:7001            0.0.0.0:*               LISTEN      1250/nxnode.bin     
tcp        0      0 127.0.0.1:25001         0.0.0.0:*               LISTEN      1345/nxrunner.bin   
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:3001          0.0.0.0:*               LISTEN      1316/pipewire
......


补充:
1) -n 不解析名称
2) -t 显示 tcp 端口
3) -u 显示 udp 端口
4) -l 显示服务器接口
5) -a 显示所有接口
6) -p 显示 PID 或者程序名称的接口

案例二:显示所有端口同时显示计时器

mingyuzhu@mingyuzhu:~$ netstat -W -neopa
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name     Timer
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      991        6431       -                    off (0.00/0/0)
tcp        0      0 0.0.0.0:7001            0.0.0.0:*               LISTEN      1001       11218      1250/nxnode.bin      off (0.00/0/0)
tcp        0      0 127.0.0.1:25001         0.0.0.0:*               LISTEN      1001       11498      1345/nxrunner.bin    off (0.00/0/0)
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      0          6018433    -                    off (0.00/0/0)
tcp        0      0 127.0.0.1:3001          0.0.0.0:*               LISTEN      1001       12293      1316/pipewire        off (0.00/0/0)
tcp        0      0 0.0.0.0:4000            0.0.0.0:*               LISTEN      121        11121      -                    off (0.00/0/0)
tcp        0      0 127.0.0.1:26001         0.0.0.0:*               LISTEN      1001       11426      1250/nxnode.bin      off (0.00/0/0)
tcp        0      0 127.0.0.1:26002         0.0.0.0:*               LISTEN      1001       6513629    1065010/nxnode.bin   off (0.00/0/0)
......


补充:
1) -W 不缩写 IP 地址
2) -n 不解析名称
3) -e 显示更多的信息
4) -o 显示计时器
5) -p 显示 PID 或者程序名称的接口
6) -a 显示所有接口

案例三:显示所有已被远程连接的端口

# netstate -apn


补充:
1) -a 显示所有接口
2) -n 不解析名称
2) -p 显示 PID 或者程序名称的接口