[命令] Linux 命令 seq (显示数字序列)

内容一:seq 命令格式

1) seq <option> <first number>
2) seq <option> <first number> <last number>
3) seq <option> <first number> <increment> <last number>

内容二:seq 命令的选项

1) -f 指定序列的格式
2) -s 指定序列的间隔符
3) -w 使序列宽度相同
4) –equal-width 使序列宽度相同

内容三:seq 命令的使用案例

3.1 案例一:seq 显示普通的数字序列

3.1.1 显示从 1 到某个数字到数字序列
# seq 5
1
2
3
4
5

(补充:这里以显示 1 到 5 的数字序列为例)

3.1.2 显示从某个数字开始到某个数字结束的数字序列
# seq 3 7
3
4
5
6
7

(补充:这里以显示 3 到 7 的数字序列为例)

3.1.3 显示从某个数字开始到某个数字结束有数值差距的数字序列
# seq 4 2 8
4
6
8

(补充:这里以显示 4 到 8 数值差距为 2 的数字序列为例)

3.2 案例二:seq 显示指定前缀的数字序列

3.2.1 显示将某个字符串作为前缀的数字序列
# seq -f "num%g" 5
num1
num2
num3
num4
num5

(补充:这里以显示 1 到 5 并且将 num 作为前缀的数字序列为例)

3.2.2 显示将某个字符串和几个空格作为前缀的数字序列
# seq -f "num%3g" 5
num  1
num  2
num  3
num  4
num  5

(补充:这里以显示 1 到 5 并且将 num 和 2 个空格作为前缀的数字序列为例)

3.2.3 显示将某个字符串和几个字符作为前缀的数字序列
# seq -f "num%03g" 5
num001
num002
num003
num004
num005

(补充:这里以显示 1 到 5 并且将 num 和 2 个 0 作为前缀的数字序列为例)

3.3 案例三:seq 显示指定间隔符的数字序列

3.3.1 显示没有间隔符的数字序列
# seq -s '' 5
12345

(补充:这里以显示 1 到 5 并且没有间隔符的数字序列为例)

3.3.2 显示间隔符是空格的数字序列
# seq -s ' ' 5
1 2 3 4 5

(补充:这里以显示 1 到 5 并且以空格作为间隔的数字序列为例)

3.3.3 显示间隔符是某个字符的数字序列
# seq -s '#' 5
1#2#3#4#5

(补充:这里以显示 1 到 5 并且以 # 作为间隔的数字序列为例)

3.4 案例四:seq 显示指定宽度的数字序列

# seq -w 1 10
01
02
03
04
05
06
07
08
09
10

或者:

# seq --equal-width 1 10
01
02
03
04
05
06
07
08
09
10

3.5 案例五:seq 使用变量显示数字序列

# a=5
# seq $a
1
2
3
4
5

(补充:这里以将变量 a 的值设置为 5 ,并且显示 1 到变量 a 的值的数字变量为例)

3.6 案例六:将 seq 显示的数字序列导入到一个文件里

# seq 1 5 > test.txt
# cat test.txt
1
2
3
4
5

或者:

# seq 1 5 | xargs -I{} echo {} > test.txt

# cat test.txt
1
2
3
4
5

(补充:这里以显示 1 到 5 的数字序列并导入到 test.txt 文件为例)

[步骤] 系统升级 (从 openSUSE Leap 15.2 升级到 openSUSE Leap 15.3)

步骤一:显示现在的系统版本

# cat /etc/*release*
NAME="openSUSE Leap"
VERSION="15.2"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.2"
PRETTY_NAME="openSUSE Leap 15.2"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.2"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"

(注意:确保显示的系统版本是 openSUSE Leap 15.2)

步骤二:准备升级

2.1 确认已使用的软件库

# zypper ls -d
#  | Alias                     | Name                               | Enabled | GPG Check | Refresh | Priority | Type   | URI
---+---------------------------+------------------------------------+---------+-----------+---------+----------+--------+---------------------------------------------------------------------------------------------
1  | repo-non-oss              | Non-OSS Repository                 | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/distribution/leap/15.2/repo/non-oss/
2  | repo-oss                  | Main Repository                    | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/distribution/leap/15.2/repo/oss/
3 | repo-update               | Main Update Repository             | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.2/oss/
4 | repo-update-non-oss       | Update Repository (Non-Oss)        | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.2/non-oss/

(补充:确保以上库已处于 Enabled 状态)

2.2 刷新已使用的软件库

# zypper ref

(注意:确保刷新成功,否则请检查网络)

2.3 升级到 openSUSE Leap 15.2

# zypper -n update

2.4 用 releasever 变量替换所有版本号

# sed -i 's/15.2/${releasever}/g' /etc/zypp/repos.d/*.repo

步骤三:升级系统

3.1 将版本号设置为 15.3 并刷新

# zypper --releasever=15.3 refresh

3.2 提前下载并安装 openSUSE Leap 15.3 所需的软件包

# zypper --releasever=15.3 dup --download-in-advance

3.3 升级系统

# zypper --releasever=15.3 dup

3.4 重启系统

# reboot

步骤四:后续检查

4.1 显示升级后的系统版本

# cat /etc/*release*
NAME="openSUSE Leap"
VERSION="15.3"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.3"
PRETTY_NAME="openSUSE Leap 15.3"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.3"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"

4.2 显示升级后已使用的软件库

# zypper ls -d
#  | Alias                     | Name                                                         | Enabled | GPG Check | Refresh | Priority | Type   | URI
---+---------------------------+------------------------------------+---------+-----------+---------+----------+--------+---------------------------------------------------------------------------------------------
1  | repo-non-oss              | Non-OSS Repository                                           | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/distribution/leap/15.3/repo/non-oss/
2  | repo-oss                  | Main Repository                                              | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/distribution/leap/15.3/repo/oss/
3 | repo-update                | Main Update Repository                                       | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/oss/
4 | repo-update-non-oss        | Update Repository (Non-Oss)                                  | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/non-oss/
4  | repo-backports-update     | Update repository of openSUSE Backports                      | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/backports/
5  | repo-sle-update           | Update repository with updates from SUSE Linux Enterprise 15 | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/sle/

(注意:升级到 openSUSE Leap 15.3 系统后,自动新增加了 repo-backports-update 软件库和 repo-sle-update 软件库)

[命令] 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 里的所有内容为例)