[命令] 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 软件库)

[消息] 永恒中心 (Eternal Center) 第 500 次 post


永恒中心 (Eternal Center) 第 500 次 post 啦!

我曾今在洞察历史的过程中,逐步了解到了一场场承前启后的社会思潮,一位位创造奇迹的科学家、发明家、思想家、艺术家,一个个让未来变得无限可能和美好的时代。他们塑造着我们今天的生活方式以及支撑这些生活方式的科学和哲学奇迹。

亚里士多德、达芬奇、特斯拉等这类人物的诞生,内燃机、青霉素、互联网等这类技术的发明,如果要让这些希望的蛛丝马迹出现,唯有一个开放、共享、公平、守信、不分国界和文化的大环境。

理查德、李纳斯和维德纽斯等人所开创和坚持的开源理念,让这一切在互联网技术领域成为了现实。

于是,我创建了分享开源技术和知识的网站 永恒中心 (Eternal Center),并相信我每一次为开源领域添砖加瓦的努力和牺牲,都是在为自己、自己身边的人和我们的星球赢得未来。

开源的知识和技术,其知识产权属于全世界每一个人,不分国籍、信仰、种族,不会被任何性质的个人、团队、公司、政府所垄断,几乎没有不平等的财富或权利的入门成本,只需依靠自身的投入和努力,就能在这个平台里,在不需要看任何其他个人、团队、公司、政府的脸色情况下,成就自我。

祝大家身体健康、生活愉快、能为自己所从事的事情感到骄傲和自豪,我们下一个 500 post 再见!