[命令] Linux 命令 echo (显示内容)

内容一:echo 的命令选项

1) -n 输出不换行
2) -e 处理某些特殊字符
\a 蜂鸣声报警
\b 删除前面一个字符
\c 在末尾不换行
\e 输出 esc
\f 换行,同时光标停在原处
\n 换行
\r 不换行,同时光标停在原处
\t tab,水平方向
\v tab,垂直方向
\ 输出 \
\Onnn 输出八进制 ASCII 字符
\xHH 输出十六进制 ASCII 字符
3) -E 不再转义

内容二:echo 的其他显示选项

1) \033[0m 将所有显示属性关闭
2) \033[1m 高亮
3) \033[4m 下划线
4) \033[5m 闪烁
5) \033[7m 反显
6) \033[8m 消隐
7) \033[37m — \33[0m 设置字体颜色,这里以将字体颜色设置为白色为例
8) \033[40m — \33[0m 设置背景颜色,这里以将背景颜色设置为白色为例
9) \033[A 将光标向上移 n 行
10) \033[B 将光标向下移 n 行
11) \033[C 将光标向右移 n 行
12) \033[D 将光标向左移 n 行
13) \033[;H 将光标跳转到 x 和 y 位置
14) \033[2J 清屏
15) \033[K 将光标所在位置到行尾的所有位置全部清除
16) \033[s 将光标位置保存
17) \033[u 将光标位置恢复
18) \033[?25l 将光标隐藏
19) \033[?25h 将光标显示

内容三:echo 显示不同颜色字体的案例

# echo -e "\033[30m black characters \033[0m" 
# echo -e "\033[31m red characters \033[0m"
# echo -e "\033[32m green characters \033[0m" 
# echo -e "\033[33m yellow characters \033[0m"
# echo -e "\033[34m blue characters \033[0m"
# echo -e "\033[35m purple character \033[0m"
# echo -e "\033[36m sky blue character \033[0m"
# echo -e "\033[37m white character \033[0m"

内容四:echo 显示不同颜色背景的案例

# echo -e "\033[40;37m white characters on black background \033[0m"
# echo -e "\033[41;37m white characters on red background \033[0m"
# echo -e "\033[42;37m white characters on green background \033[0m"
# echo -e "\033[43;37m white characters on yellow background \033[0m"
# echo -e "\033[44;37m white characters on blue background \033[0m"
# echo -e "\033[45;37m white characters on purple background \033[0m"
# echo -e "\033[46;37m white characters on sky blue background \033[0m"
# echo -e "\033[47;30m black characters on white background \033[0m"

内容五:echo 的其他案例

5.1 案例一:不换行带 tab 输出

# for month in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec;do echo -e "$month\t\c";done
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

(补充:这里以不换行带 tab 输出 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 为例)

5.2 案例二:先清屏再不换行输出

# echo -e "\033[2J\033[10A\Eternal Center\c"

(补充:这里以先清屏再不换行输出 Eternal Center 为例)

[命令] Linux 命令 tee (将输出内容保存到文件里)

内容一:tee 命令的格式

# tee [option] [file]......

内容二:tee 命令的选项

1) -a 或者 –append 将输出内容添加到文件里内容的末尾
2) -i 或者 –ignore-interrupts 忽略中断信号
3) –help 显示帮助信息
4) –version 显示版本信息

内容三:tee 的使用案例

3.1 将输出内容添加到另一个文件里内容的末尾

# echo 'tee test' | tee -a test.txt
tee test
# tail -1 test.txt
tee test

(补充:这里以将输出内容 ‘tee test’ 添加到另一个文件 test.txt 里内容的末尾为例)

3.2 将文件内容添加到另一个文件里内容的末尾

# cat test1.txt | tee -a test2.txt
test1
# tail -1 test2.txt
test1

(补充:这里以将 test1.txt 文件里的内容添加到另一个文件 test2.txt 里内容的末尾为例)

3.3 将输出内容变成另一个文件里的所有内容

# echo 'tee test' | tee test.txt
tee test
# cat test.txt
tee test

(补充:这里以将输出内容 ‘tee test’ 变成另一个文件 test.txt 里的所有内容为例)

3.4 将文件内容变成另一个文件里的所有内容

# cat test1.txt | tee -a test2.txt
test1
# cat test2.txt
test1

(补充:这里以将 test1.txt 文件里的内容变成另一个文件 test2.txt 里的所有内容为例)

[内容] CVE 简介

内容一:什么叫 CVE

CVE 全称是:Common Vulnerabilities and Exposures,翻译成中文是:常见脆弱性和暴露,是一个业界统一的脆弱性和暴露。

内容二:CVE 的常用格式

CVE-2016-4658,其中 2016-4658 是编号

内容三:CVE 的用途

用于标签系统和应用的漏洞,并实现了一个漏洞数据库以进行漏洞的查询和管理

内容四:CVE 的网站

4.1 CVE 官方网站

https://www.cvedetails.com

4.2 RedHat CVE 官方网站

4.2.1 RedHat CVE 官方网站

https://access.redhat.com/security/security-updates/#/cve

4.2.2 RedHat CVE 勘误官方网站

https://access.redhat.com/management/errata

4.3 openSUSE CVE 官方网站

openSUSE CVE 安全补丁官方网站

https://lists.opensuse.org/archives/list/security-announce@lists.opensuse.org/

4.4 SUSE CVE 官方网站

SUSE CVE 安全补丁官方网站

https://www.suse.com/security/cve/

内容五:显示软件 CVE 信息

5.1 显示软件 CVE 信息的变更历史

# rpm -q openssh-clients --changelog | grep -i cve

(补充:这里以显示 openssh-clients 软件的 CVE 信息的变更历史为例)

5.2 显示软件现在的版本是否修复 CVE 漏洞

# rpm -qpi --changelog redis-6.0.14-6.8.1.x86_64.rpm |grep -E '32675'
- Fix CVE-2021-32675, Denial Of Service when processing RESP request
  (CVE-2021-32675, bsc#1191303)
  * cve-2021-32675.patch

(补充:这里以确认 redis-6.0.14-6.8.1.x86_64.rpm 软件包是否已修复 CVE-2021-32675 为例)

[工具] Shell 读取一个文件 (以列的方式)

介绍

作者:朱明宇
名称:读取 1 个文件(以列的方式)
作用:读取 1 个文件,并把里面的内容以空格作为分割符,分成 3 列显示出来

使用方法:
1. 给此脚本添加执行权限
2. 执行此脚本,并在输入此命令时,在后面添加要被读取文件

脚本

#!/bin/bash

file=$1

if [[ $# -lt 1 ]];then
        echo "This file does not exist"
        exit
fi

while read -r f1 f2 f3
do
        echo "file 1:$f1 ==> file 2:$f2 ==> file 3:$f3"

done < "$file"

[工具] Shell 读取一个文件 (以行的方式)

介绍

作者:朱明宇
名称:读取 1 个文件(以行的方式)
作用:读取 1 个文件(以行的方式),并把里面的内容显示出来

使用方法:
1. 给此脚本添加执行权限
2. 执行此脚本,并在输入此命令时,在后面添加要被读取文件

脚本

#!/bin/bash

file=$1

if [[ $# -lt 1 ]];then
        echo "This file does not exist"
        exit
fi

while read line
do
        echo "$line"

done < "$file"