linux-day01
用户登录
- root用户
- 是一个特殊的管理账号,也可以成为超级管理员
- root用户对系统有完全控制的权限
- 对系统的损害会无限大
- 在工作中,如果没有特殊的必要,尽量不要使用root
- 普通用户
- 权限有限
- 对系统的损害会小
终端
分类
- 设备终端
- 物理终端
- 虚拟终端 ctrl+alt+f[1-6] /dev/tty#
- 图形终端 /dev/tty7
- 串行终端
- 伪终端 通过ssh远程连接的 /dev/pts/#
- 查看终端的命令 tty
- 查看ip地址的命令 ip addr
交互式接口
启动终端以后,在终端设备上附加的一个应用程序
- GUI(桌面)
- CLI command line
- powershell
- sh
- bash(linux,mac默认的程序)
- zsh
- csh
- tcsh
bash
bash是linux系统的用户界面,提供了用户和操作系统之间的交互,它接收用户的输入,让它送给操作系统执行
-
目前是linux和mac上默认的shell
-
centos默认使用
-
显示系统当前使用的shell echo $SHELL
-
查看系统内可以使用的shell cat /etc/shells
-
ctrl +d 快速终止当前的连接
-
切换shell chsh -s shell
-
echo $SHELL # 显示默认 Shell
-
echo $0 # 显示当前运行的 Shell
修改ssh连接慢的步骤
[root@localhost ~]# grep -i "dns" /etc/ssh/sshd_config
#UseDNS yes
[root@localhost ~]# echo "UseDNS no" >> /etc/ssh/sshd_config
[root@localhost ~]# systemctl restart sshd
命令提示符
[root@localhost ~]#
管理员是# 普通用户时$
显示提示符格式
[root@localhost ~]# echo $PS1
[\u@\h \W]\$
\u 代表当前登录的用户
\h 代表当前主机的主机名
\W 代表当前的目录
0表示默认字体,1表示加粗,4在字体下方加下划线 5 闪烁 7 代表突出显示 ---这些都可以组合
31-37 字体颜色
40-47 表示背景颜色
echo 'PS1="\[\e[1;35mm\][\u@\h \W]\\$\[\e[0m\]"' >> /etc/profile.d/ps.sh #永久生效
追加到配置文件中之后,退出重新连接中端会生效、或者 重新加载一下配置文件:source /etc/profile.d/ps.sh
PS1="\[\e[1;5;41;33m\][\u@\h \W]\\$\[\e[0m\]"
注:Shell 不是 Bash,当执行 echo $PS1 时,系统返回 PS1: Undefined variable.
[root@localhost ~]# echo $PS1
PS1: Undefined variable.
[root@localhost ~]# echo $SHELL
/bin/csh
[root@localhost ~]# echo $0
-csh
命令
执行命令: 输入命令回车
内部命令:shell 自带的命令
- help 显示所有的内部命令
外部命令:第三方提供的命令
查看命令的类型: type
[root@localhost ~]#type echo
echo is a shell builtin
[root@localhost ~]#type top
top is /usr/bin/top
别名
- 查看当前所有的别名 alias
- 自定别名 alias cdetc='cd /etc'
- 取消别名 unalias cdetc
- 设置别名只对当前的终端有效
- 设置所有用户都可以用 /etc/bashrc:
[root@localhost /]#echo "alias cdetc='cd /etc'" >> etc/bashrc
[root@localhost ~]#source /etc/bashrc
[root@localhost ~]#cdetc
[root@localhost etc]#
- 只对当前用户有效 ~/.bashrc
[root@localhost /]#echo "alias cdsys='cd /etc/sysconfig'" >> ~/.bashrc
[root@localhost /]#cdsys
bash: cdsys: command not found...
[root@localhost /]#source ~/.bashrc
[root@localhost /]#cdsys
[root@localhost sysconfig]#
- 执行本身命令
- \command \ls
- "command" "ls"
- 'command' 'ls'
- path \usr\bin\ls
[root@localhost ~]#alias cdetc='cd /etc'
[root@localhost ~]#alias
alias cdetc='cd /etc'
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
命令格式
command [options.....] [args...]
command 命令本身
options:启动或者关闭命令里面的某些功能
- 长选项:--help --color
- 短选项: -i -l
[root@localhost etc]#ll
[root@localhost etc]#ls -l -a
args:命令的作用体,一般情况下是目录或者文件,用户名等等
[root@localhost etc]#ls -l /etc/sysconfig/
注意:
- 短选项是可以合并
- 空格隔开
- ctrl+c 结束命令的执行
- 在同一行执行多个命令用;隔开
- 一个命令可以在多行显示用\连接
获取命令的帮助信息
内部命令:
- help command
- man bash
外部命令:
- command -h
[root@localhost etc]#top -h
procps-ng version 3.3.10
Usage:
top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
- command --help
[root@localhost etc]#top --help
top: inappropriate '-help'
Usage:
top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
- man coomand
- 官方文档
[root@localhost ~]#python --help
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
[] 可选项
<> 表示变化的数据
... 表示列表
a|b|c 或者
-abc 表示-a -b -c
{} 表示分组
man
1 Executable programs or shell commands #用户命令
2 System calls (functions provided by the kernel) # 系统调用
3 Library calls (functions within program libraries) # 库的调用
4 Special files (usually found in /dev) #设备文件与特殊文件
5 File formats and conventions eg /etc/passwd # 配置文件格式
6 Games #游戏
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) # 杂项
8 System administration commands (usually only for root) # 管理类的命令
9 Kernel routines [Non standard] # 内核的API
退出q
翻屏 空格
翻行 回车
man 章节 passwd
bash 快捷键
- ctrl+l 清屏 相当于clear
- ctrl+o 执行当前的命令,并显示当前的命令
- ctrl+s 锁屏
- ctrl+q 解锁
- ctrl+c 终止命令
- ctrl+z 挂起命令
- ctrl+a 光标移动到行首,相当于Home
- ctrl+e 光标移动到行位,相当于End
- ctrl+xx 在开头和当前光标所在位置跳转
- ctrl+k 删除光标后的文字
- ctrl+u 删除光标前的文字
- alt+r 删除正行
tab 键
- 命令补全
- 内部命令
- 外部命令:根据环境变量定义的路径,从前往后依次查找,自动匹配第一个查找到的内容
- 如果用户给的命令只有唯一一个匹配,则直接补全
- 如果有多个匹配,则需要在按tab键将所有匹配到的结果展示出来
- 目录补全
- 把用户给定的字符作为文件的开头,如果有唯一一个匹配则直接补全
- 如果有多个匹配,则需要再次按tab键把所有的匹配到的结果展示出来
引号
[root@localhost ~]#name=alexdsb
[root@localhost ~]#echo "$name"
alexdsb
[root@localhost ~]#echo '$name'
$name
[root@localhost ~]#echo "wo shi `tty`"
wo shi /dev/pts/2
[root@localhost ~]#tty
/dev/pts/2
[root@localhost ~]#echo "wo shi $(tty)"
wo shi /dev/pts/2
命令历史
- 可以使用上下箭头来查找之前执行过的命令
- 存放文件是~/.bash_history
- 执行的命令是history
- 执行上一条命令
- 上箭头
- !!
- !-1
- ctrl+p 回车
- 调用上一条命令的最后一个值 esc .
- !# 指定第多少条命令
- !-# 指定倒数第#条命令
- !string 用来最近一次匹配到的命令(从下往上)
- ctrl+r 搜索命令
- ctrl+g 取消搜索
- history #或者history # 显示最后#条命令(包括当前命令)
命令展开
touch file{1..20}
seq 0 2 10
echo file{1..20..2}
echo:
[root@localhost ~]#echo file{1,2,3}
file1 file2 file3
[root@localhost ~]#echo file{1..20}
file1 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12 file13 file14 file15 file16 file17 file18 file19 file20
[root@localhost ~]#echo file{1..20..2}
file1 file3 file5 file7 file9 file11 file13 file15 file17 file19
seq:
[root@localhost ~]#seq 1 10
1
2
3
4
5
6
7
8
9
10
[root@localhost ~]#seq 1 2 10
1
3
5
7
9
touch:
[root@localhost ~]#touch file{1..10}
[root@localhost ~]#ll
total 8
-rw-------. 1 root root 1733 Aug 11 20:15 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Desktop
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Documents
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Downloads
-rw-r--r--. 1 root root 0 Aug 14 20:48 file1
-rw-r--r--. 1 root root 0 Aug 14 20:48 file10
-rw-r--r--. 1 root root 0 Aug 14 20:48 file2
-rw-r--r--. 1 root root 0 Aug 14 20:48 file3
-rw-r--r--. 1 root root 0 Aug 14 20:48 file4
-rw-r--r--. 1 root root 0 Aug 14 20:48 file5
-rw-r--r--. 1 root root 0 Aug 14 20:48 file6
-rw-r--r--. 1 root root 0 Aug 14 20:48 file7
-rw-r--r--. 1 root root 0 Aug 14 20:48 file8
-rw-r--r--. 1 root root 0 Aug 14 20:48 file9
-rw-r--r--. 1 root root 1781 Aug 11 20:17 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Music
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Pictures
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Public
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Templates
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Videos
[root@localhost ~]#rm -f file{1..10}
[root@localhost ~]#ll
total 8
-rw-------. 1 root root 1733 Aug 11 20:15 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Desktop
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Documents
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Downloads
-rw-r--r--. 1 root root 1781 Aug 11 20:17 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Music
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Pictures
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Public
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Templates
drwxr-xr-x. 2 root root 6 Aug 11 20:20 Videos
echo 回显
[root@localhost ~]#echo -e 'sdfsdf\nsadfdsaf'
sdfsdf
sadfdsaf
echo -e '\a' #播放声音
查看用户登录信息
[root@localhost ~]#whoami # 显示当前的登录用户
root
[root@localhost ~]#who am i #显示当前登录用户的详细信息
root pts/2 2019-08-22 15:54 (192.168.21.1)
[root@localhost ~]#w 显示所有的用户并显示执行的命令
16:27:54 up 5:19, 9 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty2 11:37 4:48m 0.02s 0.02s -bash
wu tty3 11:39 4:48m 0.02s 0.02s -bash
root :0 :0 11:30 ?xdm? 1:28 0.36s /usr/libexec/gnome-session-binary --session gnome-classi
root pts/0 :0 11:35 4:43m 0.03s 0.03s bash
root pts/1 192.168.21.1 12:11 4:03m 0.02s 0.02s -bash
root pts/2 192.168.21.1 15:54 2.00s 0.18s 0.03s w
wu pts/3 192.168.21.1 12:27 2:26 0.05s 0.05s -bash
date
[root@localhost ~]#date 显示当前的时间
Thu Aug 22 16:30:06 CST 2019
Usage: date [OPTION]... [+FORMAT]
or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
[root@localhost ~]#date 010923102018 #修改时间
Tue Jan 9 23:10:00 CST 2018
[root@localhost ~]#date
Tue Jan 9 23:10:18 CST 2018
[root@localhost ~]#ntpdate time.windows.com #同步网络服务器时间
unix元年 1970-01-01
[root@localhost ~]#date
Thu Aug 22 16:35:44 CST 2019
[root@localhost ~]#date
Thu Aug 22 16:35:47 CST 2019
[root@localhost ~]#date
Thu Aug 22 16:35:48 CST 2019
[root@localhost ~]#date +%a
Thu
[root@localhost ~]#date +%A
Thursday
[root@localhost ~]#date +%F
2019-08-22
[root@localhost ~]#date +%H
16
[root@localhost ~]#date +%I
04
[root@localhost ~]#date +%m
08
[root@localhost ~]#date +%d
22
[root@localhost ~]#date +%M
38
[root@localhost ~]#date +%h
Aug
[root@localhost ~]#date +%c
Thu 22 Aug 2019 04:38:42 PM CST
[root@localhost ~]#date +%T
16:39:01
[root@localhost ~]#date +%y
19
[root@localhost ~]#date +%Y
2019
[root@localhost ~]#date +%Y/m/%d
2019/m/22
[root@localhost ~]#date +%Y/%m/%d
2019/08/22
[root@localhost ~]#date +%s
1566463197
[root@localhost ~]#date +%W
33
############ 2025年8月14日笔记 ##############
[root@localhost ~]#date
Thu Aug 14 21:03:15 CST 2025
[root@localhost ~]#date -u
Thu Aug 14 13:03:43 UTC 2025
[root@localhost ~]#date %MM
date: invalid date ‘%MM’
[root@localhost ~]#date +%MM
07M
[root@localhost ~]#date +%DD
08/14/25D
[root@localhost ~]#date +%hh
Augh
[root@localhost ~]#date +%CC
20C
[root@localhost ~]#date +%YY
2025Y
[root@localhost ~]#date +%ss --- 当前时间戳
1755176988s
[root@localhost ~]#date +%a --- 星期几的简称
Thu
[root@localhost ~]#date +%A --- 星期几的全称
Thursday
[root@localhost ~]#date +%F --- 年月日
2025-08-14
[root@localhost ~]#date +%H --- 二十四小时制的九点
21
[root@localhost ~]#date +%I --- 十二小时制的九点
09
[root@localhost ~]#date +%m --- 月
08
[root@localhost ~]#date +%d --- 日
14
[root@localhost ~]#date +%M --- 分钟
22
[root@localhost ~]#date +%h --- 月
Aug
[root@localhost ~]#date +%c
Thu 14 Aug 2025 09:22:55 PM CST
[root@localhost ~]#date +%T --- 时分秒
21:25:48
[root@localhost ~]#date +%y --- 年
25
[root@localhost ~]#date +%Y --- 年
2025
[root@localhost ~]#date +%Y/%m/%d --- 自定义年月日格式
2025/08/14
[root@localhost ~]#date +%s --- 当前时间戳,从1970年1月1日0时0分0秒,unix元年
1755178078
[root@localhost ~]#date +%W --- 今年到现在过了多少周
32
[root@localhost ~]#time
time timedatectl timeout times
[root@localhost ~]#timedatectl
Local time: Tue 2025-08-19 20:03:11 CST
Universal time: Tue 2025-08-19 12:03:11 UTC
RTC time: Tue 2025-08-19 12:03:11
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@localhost ~]#timeout
Try 'timeout --help' for more information.
[root@localhost ~]#times
0m0.008s 0m0.038s
0m0.013s 0m0.110s
[root@localhost ~]#date
Thu Aug 14 21:10:06 CST 2025
[root@localhost ~]#date 010923102018 ---更改当前系统时间
Tue Jan 9 23:10:00 CST 2018
[root@localhost ~]#date
Tue Jan 9 23:10:30 CST 2018
[root@localhost ~]#ntpdate time.windows.com --- 恢复当前系统时间,同步网络时间到本地
14 Aug 21:14:33 ntpdate[3562]: step time server 20.189.79.72 offset 239666466.004369 sec
[root@localhost ~]#date --help
Usage: date [OPTION]... [+FORMAT]
or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.
Mandatory arguments to long options are mandatory for short options too.
-d, --date=STRING display time described by STRING, not 'now'
-f, --file=DATEFILE like --date once for each line of DATEFILE
-I[TIMESPEC], --iso-8601[=TIMESPEC] output date/time in ISO 8601 format.
TIMESPEC='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns' for date
and time to the indicated precision.
-r, --reference=FILE display the last modification time of FILE
-R, --rfc-2822 output date and time in RFC 2822 format.
Example: Mon, 07 Aug 2006 12:34:56 -0600
--rfc-3339=TIMESPEC output date and time in RFC 3339 format.
TIMESPEC='date', 'seconds', or 'ns' for
date and time to the indicated precision.
Date and time components are separated by
a single space: 2006-08-07 12:34:56-06:00
-s, --set=STRING set time described by STRING
-u, --utc, --universal print or set Coordinated Universal Time (UTC)
--help display this help and exit
--version output version information and exit
FORMAT controls the output. Interpreted sequences are:
%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
%b locale's abbreviated month name (e.g., Jan)
%B locale's full month name (e.g., January)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 20)
%d day of month (e.g., 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric time zone (e.g., -0400)
%:z +hh:mm numeric time zone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
By default, date pads numeric fields with zeroes.
The following optional flags may follow '%':
- (hyphen) do not pad the field
_ (underscore) pad with spaces
0 (zero) pad with zeros
^ use upper case if possible
# use opposite case if possible
After any flags comes an optional field width, as a decimal number;
then an optional modifier, which is either
E to use the locale's alternate representations if available, or
O to use the locale's alternate numeric symbols if available.
Examples:
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Show the time on the west coast of the US (use tzselect(1) to find TZ)
$ TZ='America/Los_Angeles' date
Show the local time for 9AM next Friday on the west coast of the US
$ date --date='TZ="America/Los_Angeles" 09:00 next Fri'
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'date invocation'
显示时区
[root@localhost ~]#timedatectl
Local time: Thu 2019-08-22 16:42:43 CST
Universal time: Thu 2019-08-22 08:42:43 UTC
RTC time: Thu 2019-08-22 08:42:43
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@localhost ~]#timedatectl set-timezone Asia/Tokyo
[root@localhost ~]#timedatectl set-
set-local-rtc set-ntp set-time set-timezone
[root@localhost ~]#timedatectl set-timezone
Display all 425 possibilities? (y or n)
Africa/Abidjan America/Grenada Asia/Anadyr Europe/Bratislava
Africa/Accra America/Guadeloupe Asia/Aqtau Europe/Brussels
Africa/Addis_Ababa America/Guatemala Asia/Aqtobe Europe/Bucharest
Africa/Algiers America/Guayaquil Asia/Ashgabat Europe/Budapest
Africa/Asmara America/Guyana Asia/Atyrau Europe/Busingen
Africa/Bamako America/Halifax Asia/Baghdad Europe/Chisinau
Africa/Bangui America/Havana Asia/Bahrain Europe/Copenhagen
Africa/Banjul America/Hermosillo Asia/Baku Europe/Dublin
Africa/Bissau America/Indiana/Indianapolis Asia/Bangkok Europe/Gibraltar
Africa/Blantyre America/Indiana/Knox Asia/Barnaul Europe/Guernsey
Africa/Brazzaville America/Indiana/Marengo Asia/Beirut Europe/Helsinki
Africa/Bujumbura America/Indiana/Petersburg Asia/Bishkek Europe/Isle_of_Man
Africa/Cairo America/Indiana/Tell_City Asia/Brunei Europe/Istanbul
Africa/Casablanca America/Indiana/Vevay Asia/Chita Europe/Jersey
Africa/Ceuta America/Indiana/Vincennes Asia/Choibalsan Europe/Kaliningrad
Africa/Conakry America/Indiana/Winamac Asia/Colombo Europe/Kiev
Africa/Dakar America/Inuvik Asia/Damascus Europe/Kirov
Africa/Dar_es_Salaam America/Iqaluit Asia/Dhaka Europe/Lisbon
Africa/Djibouti America/Jamaica Asia/Dili Europe/Ljubljana
Africa/Douala America/Juneau Asia/Dubai Europe/London
Africa/El_Aaiun America/Kentucky/Louisville Asia/Dushanbe Europe/Luxembourg
Africa/Freetown America/Kentucky/Monticello Asia/Famagusta Europe/Madrid
Africa/Gaborone America/Kralendijk Asia/Gaza Europe/Malta
Africa/Harare America/La_Paz Asia/Hebron Europe/Mariehamn
Africa/Johannesburg America/Lima Asia/Ho_Chi_Minh Europe/Minsk
Africa/Juba America/Los_Angeles Asia/Hong_Kong Europe/Monaco
Africa/Kampala America/Lower_Princes Asia/Hovd Europe/Moscow
Africa/Khartoum America/Maceio Asia/Irkutsk Europe/Oslo
Africa/Kigali America/Managua Asia/Jakarta Europe/Paris
Africa/Kinshasa America/Manaus Asia/Jayapura Europe/Podgorica
Africa/Lagos America/Marigot Asia/Jerusalem Europe/Prague
Africa/Libreville America/Martinique Asia/Kabul Europe/Riga
Africa/Lome America/Matamoros Asia/Kamchatka Europe/Rome
Africa/Luanda America/Mazatlan Asia/Karachi Europe/Samara
Africa/Lubumbashi America/Menominee Asia/Kathmandu Europe/San_Marino
Africa/Lusaka America/Merida Asia/Khandyga Europe/Sarajevo
Africa/Malabo America/Metlakatla Asia/Kolkata Europe/Saratov
Africa/Maputo America/Mexico_City Asia/Krasnoyarsk Europe/Simferopol
Africa/Maseru America/Miquelon Asia/Kuala_Lumpur Europe/Skopje
Africa/Mbabane America/Moncton Asia/Kuching Europe/Sofia
Africa/Mogadishu America/Monterrey Asia/Kuwait Europe/Stockholm
Africa/Monrovia America/Montevideo Asia/Macau Europe/Tallinn
Africa/Nairobi America/Montserrat Asia/Magadan Europe/Tirane
Africa/Ndjamena America/Nassau Asia/Makassar Europe/Ulyanovsk
Africa/Niamey America/New_York Asia/Manila Europe/Uzhgorod
Africa/Nouakchott America/Nipigon Asia/Muscat Europe/Vaduz
Africa/Ouagadougou America/Nome Asia/Nicosia Europe/Vatican
Africa/Porto-Novo America/Noronha Asia/Novokuznetsk Europe/Vienna
Africa/Sao_Tome America/North_Dakota/Beulah Asia/Novosibirsk Europe/Vilnius
Africa/Tripoli America/North_Dakota/Center Asia/Omsk Europe/Volgograd
Africa/Tunis America/North_Dakota/New_Salem Asia/Oral Europe/Warsaw
Africa/Windhoek America/Nuuk Asia/Phnom_Penh Europe/Zagreb
America/Adak America/Ojinaga Asia/Pontianak Europe/Zaporozhye
America/Anchorage America/Panama Asia/Pyongyang Europe/Zurich
America/Anguilla America/Pangnirtung Asia/Qatar Indian/Antananarivo
America/Antigua America/Paramaribo Asia/Qostanay Indian/Chagos
America/Araguaina America/Phoenix Asia/Qyzylorda Indian/Christmas
America/Argentina/Buenos_Aires America/Port-au-Prince Asia/Riyadh Indian/Cocos
America/Argentina/Catamarca America/Port_of_Spain Asia/Sakhalin Indian/Comoro
America/Argentina/Cordoba America/Porto_Velho Asia/Samarkand Indian/Kerguelen
America/Argentina/Jujuy America/Puerto_Rico Asia/Seoul Indian/Mahe
America/Argentina/La_Rioja America/Punta_Arenas Asia/Shanghai Indian/Maldives
America/Argentina/Mendoza America/Rainy_River Asia/Singapore Indian/Mauritius
America/Argentina/Rio_Gallegos America/Rankin_Inlet Asia/Srednekolymsk Indian/Mayotte
America/Argentina/Salta America/Recife Asia/Taipei Indian/Reunion
America/Argentina/San_Juan America/Regina Asia/Tashkent Pacific/Apia
America/Argentina/San_Luis America/Resolute Asia/Tbilisi Pacific/Auckland
America/Argentina/Tucuman America/Rio_Branco Asia/Tehran Pacific/Bougainville
America/Argentina/Ushuaia America/Santarem Asia/Thimphu Pacific/Chatham
America/Aruba America/Santiago Asia/Tokyo Pacific/Chuuk
America/Asuncion America/Santo_Domingo Asia/Tomsk Pacific/Easter
America/Atikokan America/Sao_Paulo Asia/Ulaanbaatar Pacific/Efate
America/Bahia America/Scoresbysund Asia/Urumqi Pacific/Fakaofo
America/Bahia_Banderas America/Sitka Asia/Ust-Nera Pacific/Fiji
America/Barbados America/St_Barthelemy Asia/Vientiane Pacific/Funafuti
America/Belem America/St_Johns Asia/Vladivostok Pacific/Galapagos
America/Belize America/St_Kitts Asia/Yakutsk Pacific/Gambier
America/Blanc-Sablon America/St_Lucia Asia/Yangon Pacific/Guadalcanal
America/Boa_Vista America/St_Thomas Asia/Yekaterinburg Pacific/Guam
America/Bogota America/St_Vincent Asia/Yerevan Pacific/Honolulu
America/Boise America/Swift_Current Atlantic/Azores Pacific/Kanton
America/Cambridge_Bay America/Tegucigalpa Atlantic/Bermuda Pacific/Kiritimati
America/Campo_Grande America/Thule Atlantic/Canary Pacific/Kosrae
America/Cancun America/Thunder_Bay Atlantic/Cape_Verde Pacific/Kwajalein
America/Caracas America/Tijuana Atlantic/Faroe Pacific/Majuro
America/Cayenne America/Toronto Atlantic/Madeira Pacific/Marquesas
America/Cayman America/Tortola Atlantic/Reykjavik Pacific/Midway
America/Chicago America/Vancouver Atlantic/South_Georgia Pacific/Nauru
America/Chihuahua America/Whitehorse Atlantic/Stanley Pacific/Niue
America/Costa_Rica America/Winnipeg Atlantic/St_Helena Pacific/Norfolk
America/Creston America/Yakutat Australia/Adelaide Pacific/Noumea
America/Cuiaba America/Yellowknife Australia/Brisbane Pacific/Pago_Pago
America/Curacao Antarctica/Casey Australia/Broken_Hill Pacific/Palau
America/Danmarkshavn Antarctica/Davis Australia/Darwin Pacific/Pitcairn
America/Dawson Antarctica/DumontDUrville Australia/Eucla Pacific/Pohnpei
America/Dawson_Creek Antarctica/Macquarie Australia/Hobart Pacific/Port_Moresby
America/Denver Antarctica/Mawson Australia/Lindeman Pacific/Rarotonga
America/Detroit Antarctica/McMurdo Australia/Lord_Howe Pacific/Saipan
America/Dominica Antarctica/Palmer Australia/Melbourne Pacific/Tahiti
America/Edmonton Antarctica/Rothera Australia/Perth Pacific/Tarawa
America/Eirunepe Antarctica/Syowa Australia/Sydney Pacific/Tongatapu
America/El_Salvador Antarctica/Troll Europe/Amsterdam Pacific/Wake
America/Fortaleza Antarctica/Vostok Europe/Andorra Pacific/Wallis
America/Fort_Nelson Arctic/Longyearbyen Europe/Astrakhan UTC
America/Glace_Bay Asia/Aden Europe/Athens
America/Goose_Bay Asia/Almaty Europe/Belgrade
America/Grand_Turk Asia/Amman Europe/Berlin
日历
cal
[root@localhost ~]#cal
August 2025
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@localhost ~]#cal -y
2025
January February March
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 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
April May June
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 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30
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 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30
31
October November December
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 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30
cal -y 一年的日历
cal # 显示某一年的日历
[root@localhost ~]#cal 2023
2023
January February March
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 7 1 2 3 4 1 2 3 4
8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11
15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18
22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25
29 30 31 26 27 28 26 27 28 29 30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 6 1 2 3
2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10
9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17
16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24
23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30
30
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 1 2 3 4 5 1 2
2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9
9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16
16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23
23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30
30 31
October November December
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 7 1 2 3 4 1 2
8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
31
关机重启
- shutdown 默认1分钟之后关机
- shutdown -c 取消关机
[root@localhost ~]#shutdown
Shutdown scheduled for Tue 2025-08-19 20:11:49 CST, use 'shutdown -c' to cancel.
[root@localhost ~]#
Broadcast message from root@localhost.localdomain (Tue 2025-08-19 20:10:49 CST):
The system is going down for power-off at Tue 2025-08-19 20:11:49 CST!
shutdown -c
Broadcast message from root@localhost.localdomain (Tue 2025-08-19 20:11:00 CST):
The system shutdown has been cancelled at Tue 2025-08-19 20:12:00 CST!
- shutdown -r 重启
[root@localhost ~]#shutdown -r
Shutdown scheduled for Tue 2025-08-19 20:13:51 CST, use 'shutdown -c' to cancel.
[root@localhost ~]#
Broadcast message from root@localhost.localdomain (Tue 2025-08-19 20:12:51 CST):
The system is going down for reboot at Tue 2025-08-19 20:13:51 CST!
shutdown -c
Broadcast message from root@localhost.localdomain (Tue 2025-08-19 20:12:57 CST):
The system shutdown has been cancelled at Tue 2025-08-19 20:13:57 CST!
- TIME
- now 立即
- +n n分钟之后
- hh:mm 指定时间
[root@localhost ~]#shutdown +2
Shutdown scheduled for Tue 2025-08-19 20:16:26 CST, use 'shutdown -c' to cancel.
[root@localhost ~]#
Broadcast message from root@localhost.localdomain (Tue 2025-08-19 20:14:26 CST):
The system is going down for power-off at Tue 2025-08-19 20:16:26 CST!
shutdown -c
Broadcast message from root@localhost.localdomain (Tue 2025-08-19 20:14:30 CST):
The system shutdown has been cancelled at Tue 2025-08-19 20:15:30 CST!
[root@localhost ~]#shutdown 21:00
Shutdown scheduled for Tue 2025-08-19 21:00:00 CST, use 'shutdown -c' to cancel.
[root@localhost ~]#shutdown -c
Broadcast message from root@localhost.localdomain (Tue 2025-08-19 20:14:49 CST):
The system shutdown has been cancelled at Tue 2025-08-19 20:15:49 CST!
- 关机命令
- poweroff
- halt
- init 0
- 重启
- reboot
- -f 强制
- -p 关机
- init 6
- reboot