1.常用简单命令:
1.echo命令
2.date命令
(见第一天)
3.timedatectl命令
timedatectl命令用于显示或设置系统时间和时区
语法格式:timedatectl [参数]
timedatectl命令中的参数及作用
参数 作用
status 显示状态信息
list-timezones 列出已知时区
set-time 设置系统时间
set-timezone 设置生效时区
[root@localhost ~]# timedatectl
Local time: Sat 2021-03-20 18:34:37 CST
Universal time: Sat 2021-03-20 10:34:37 UTC
RTC time: Sun 2022-03-20 10:34:58
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
[root@localhost ~]# timedatectl status
Local time: Sat 2021-03-20 18:56:16 CST
Universal time: Sat 2021-03-20 10:56:16 UTC
RTC time: Sun 2022-03-20 10:56:37
Time zone: Asia/Shanghai (CST, +0800)
[root@localhost ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
[root@localhost ~]# timedatectl set-time 2021-03-21
[root@localhost ~]# timedatectl
Local time: Sun 2021-03-21 00:00:10 CST
Universal time: Sat 2021-03-20 16:00:10 UTC
RTC time: Sat 2021-03-20 16:00:11
Time zone: Asia/Shanghai (CST, +0800)
[root@localhost ~]# timedatectl set-time 9:00
[root@localhost ~]# timedatectl
Local time: Sun 2021-03-21 09:00:38 CST
Universal time: Sun 2021-03-21 01:00:38 UTC
RTC time: Sun 2021-03-21 01:00:38
Time zone: Asia/Shanghai (CST, +0800)
[root@localhost ~]# timedatectl set-timezone Africa/Harare
[root@localhost ~]# timedatectl
Local time: Sat 2022-03-19 18:00:58 CAT
Universal time: Sat 2022-03-19 16:00:58 UTC
RTC time: Sat 2022-03-19 16:00:59
Time zone: Africa/Harare (CAT, +0200)
4.reboot命令
reboot命令用于重启
5.poweroff命令
poweroff:关机
6.halt命令
halt:关机
使用权限:系统管理者 halt
语法格式:halt [-n] [-w] [-d] [-f] [-i] [-p]
说明:若系统的 runlevel 为 0 或 6 ,则关闭系统,否则以 shutdown 指令(加上 -h 参数)来取代
参数:
-n : 在关机前不做将记忆体资料写回硬盘的动作
-w : 并不会真的关机,只是把记录写到 /var/log/wtmp 档案里
-d : 不把记录写到 /var/log/wtmp 档案里(-n 这个参数包含了 -d) -f : 强迫关机,不呼叫
shutdown 这个指令
-i : 在关机之前先把所有网络相关的装置先停止
-p : 当关机的时候,顺便做关闭电源(poweroff)的动作
shutdown:关机(可以指定时间关机),实现halt,reboot,poweroff几个功能
7.wget命令
wget(web get)命令用于在终端命令行里下载网路文件
curl亦可下载
语法格式:wget [参数] url
先ping一下要下载的网站检测是否可以建立通讯
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=128 time=16.6 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=128 time=10.4 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=3 ttl=128 time=29.2 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=4 ttl=128 time=11.8 ms
^C
注意:此时只能通过ctrl+c停止ping
ctrl+c:中断正在执行的命令
[root@localhost ~]# wget www.baidu.com url
--2022-03-20 00:50:13-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 180.101.49.11, 180.101.49.12
Connecting to www.baidu.com (www.baidu.com)|180.101.49.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html.1’
index.html.1 100%[===================>] 2.33K --.-KB/s in 0s
2022-03-20 00:50:13 (387 MB/s) - ‘index.html.1’ saved [2381/2381]
--2022-03-20 00:50:13-- http://url/
Resolving url (url)... failed: Name or service not known.
wget: unable to resolve host address ‘url’
FINISHED --2022-03-20 00:50:28--
Total wall clock time: 15s
Downloaded: 1 files, 2.3K in 0s (387 MB/s)
wget命令中的参数以及作用
参数 作用
-b 后台下载模式
-P 下载到指定目录
-t 最大尝试次数
-c 断点续传
-p 下载页面内所有资源,包括图片、视频等
-r 递归下载
[root@localhost ~]# wget -b www.baidu.com
Continuing in background, pid 9650.
Output will be written to ‘wget-log’.
-O file:使用wget下载时,可指定下载后的文件名(正常wget下载的文件名是服务器上的文件名)
[root@localhost ~]# wget -O baidu www.baidu.com
--2022-03-20 01:06:55-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 180.101.49.11, 180.101.49.12
Connecting to www.baidu.com (www.baidu.com)|180.101.49.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘baidu’
baidu 100%[===================>] 2.33K --.-KB/s in 0s
2022-03-20 01:06:55 (304 MB/s) - ‘baidu’ saved [2381/2381]
ls:list 列出当前目录中的内容
cat:查看文件的内容(文本文件)
2.使用Bash执行命令
1.Shell命令格式:命令名 [选项] [参数]
命令名,选项,参数之间用空格隔开,多余的空格会被忽略,[]中的内容可忽略
命令名:该命令做什么
选项:该命令怎么做
参数:该命令对谁做
Linux的命令,选项,参数区分大小写,一般为小写
2.命令,选项,参数的自动补全
命令补全功能:tab键,可以自动补全命令。
自动补全规则:如果只匹配一个匹配项,按一下tab键, 它就完整补全,如果匹配多个匹配项,按两下tab键,列出匹配到的多个选项, 你接着输入字符,根据字符再去匹配。直至匹配到你想要的命令。
(历史命令,按方向键的上键,可以调出你之前执行过的命令, 按下键调整)
3.base shell提示符
PS1常用的参数含义如下:
\d :#代表日期,格式为weekday month date,例如:"Mon Aug 1"
\H :#完整的主机名称
\h :#仅取主机的第一个名字
\t :#显示时间为24小时格式,如:HH:MM:SS
\T :#显示时间为12小时格式
\A :#显示时间为24小时格式:HH:MM
\u :#当前用户的账号名称
\v :#BASH的版本信息
\w :#完整的工作目录名称
\W :#利用basename取得工作目录名称,所以只会列出最后一个目录
\# :#下达的第几个命令
\$ :#提示字符,如果是root时,提示符为:# ,普通用户则为:$
[root@localhost ~]# echo $PS1
[\u@\h \W]\$
[root@localhost ~]# PS1="[\u@\h \W]\$ \d \t \v \w \#"
[root@localhost ~]$ Sun Mar 20 01:24:09 4.4 ~ 62