linux命令cal工具介绍和案例使用

韵味老鸟 2024-08-28 14:03:15

linux 命令cal 工具介绍和案例使用

cal是一个用于在Linux终端中显示日历的命令行工具。它可以快速查看当前月份的日历,或指定特定的月份和年份

基本语法bashcal [options] [month] [year]month:要显示的月份(1-12)。year:要显示的年份(四位数)。

如果没有指定参数,cal将默认显示当前月份的日历。

常用选项-y:显示当前年份的日历。-m:将星期一设为一周的第一天。-j:以Julian日期(从1月1日开始的天数)显示日历。-3:显示当前月的前一个月、当前月和下一个月。

安装部署:

root@meng:~# which cal

root@meng:~# cal

Command 'cal' not found, but can be installed with:

apt install ncal

root@meng:~# apt install ncal

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

The following NEW packages will be installed:

ncal

0 upgraded, 1 newly installed, 0 to remove and 216 not upgraded.

Need to get 20.2 kB of archives.

After this operation, 69.6 kB of additional disk space will be used.

Get:1 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 ncal amd64 12.1.7+nmu3ubuntu2 [20.2 kB]

Fetched 20.2 kB in 2s (10.2 kB/s)

Selecting previously unselected package ncal.

(Reading database ... 75085 files and directories currently installed.)

Preparing to unpack .../ncal_12.1.7+nmu3ubuntu2_amd64.deb ...

Unpacking ncal (12.1.7+nmu3ubuntu2) ...

Setting up ncal (12.1.7+nmu3ubuntu2) ...

Processing triggers for man-db (2.10.2-1) ...

Scanning processes...

Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

命令案例:

root@meng:~# cal -h

Usage: cal [general options] [-jy] [[month] year]

cal [general options] [-j] [-m month] [year]

ncal -C [general options] [-jy] [[month] year]

ncal -C [general options] [-j] [-m month] [year]

ncal [general options] [-bhJjpwySM] [-H yyyy-mm-dd] [-s country_code] [-W number of days] [[month] year]

ncal [general options] [-Jeo] [year]

General options: [-31] [-A months] [-B months] [-d yyyy-mm]

1)显示当前日期

root@meng:~# cal

August 2024

Su Mo Tu We Th Fr Sa

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30 31

root@meng:~# ncal

August 2024

Su 4 11 18 25

Mo 5 12 19 26

Tu 6 13 20 27

We 7 14 21 28

Th 1 8 15 22 29

Fr 2 9 16 23 30

Sa 3 10 17 24 31

2)显示3个月

root@meng:~# cal -3

2024

July August September

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7

7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14

14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21

21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28

28 29 30 31 25 26 27 28 29 30 31 29 30

root@meng:~# ncal -3

July 2024 August 2024 September 2024

Su 7 14 21 28 4 11 18 25 1 8 15 22 29

Mo 1 8 15 22 29 5 12 19 26 2 9 16 23 30

Tu 2 9 16 23 30 6 13 20 27 3 10 17 24

We 3 10 17 24 31 7 14 21 28 4 11 18 25

Th 4 11 18 25 1 8 15 22 29 5 12 19 26

Fr 5 12 19 26 2 9 16 23 30 6 13 20 27

Sa 6 13 20 27 3 10 17 24 31 7 14 21 28

3)显示1年

0 阅读:0