基础命令
Linux系统的命令通常都是如下所示的格式:
命令名称 [命名参数] [命令对象]
获取登录信息 - w / who / last/ lastb。
[root ~]# w
23:31:16 up 12:16, 2 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 182.139.66.250 23:03 4.00s 0.02s 0.00s w
jackfrue pts/1 182.139.66.250 23:26 3:56 0.00s 0.00s -bash
[root ~]# who
root pts/0 2018-04-12 23:03 (182.139.66.250)
jackfrued pts/1 2018-04-12 23:26 (182.139.66.250)
[root ~]# who am i
root pts/0 2018-04-12 23:03 (182.139.66.250)
[root ~]# who mom likes
root pts/0 2018-04-12 23:03 (182.139.66.250)
[root ~]# last
root pts/0 117.136.63.184 Sun May 26 18:57 still logged in
reboot system boot 3.10.0-957.10.1. Mon May 27 02:52 - 19:10 (-7:-42)
root pts/4 117.136.63.184 Sun May 26 18:51 - crash (08:01)
root pts/4 117.136.63.184 Sun May 26 18:49 - 18:49 (00:00)
root pts/3 117.136.63.183 Sun May 26 18:35 - crash (08:17)
root pts/2 117.136.63.183 Sun May 26 18:34 - crash (08:17)
root pts/0 117.136.63.183 Sun May 26 18:10 - crash (08:42)
查看自己使用的Shell - ps。
Shell也被称为“壳”或“壳程序”,它是用户与操作系统内核交流的翻译官,简单的说就是人与计算机交互的界面和接口。目前很多Linux系统默认的Shell都是bash(Bourne Again SHell),因为它可以使用tab键进行命令和路径补全、可以保存历史命令、可以方便的配置环境变量以及执行批处理操作。
[root ~]# ps
PID TTY TIME CMD
3531 pts/0 00:00:00 bash
3553 pts/0 00:00:00 ps
查看命令的说明和位置 - whatis / which / whereis。
[root ~]# whatis ps
ps (1) - report a snapshot of the current processes.
[root ~]# whatis python
python (1) - an interpreted, interactive, object-oriented programming language
[root ~]# whereis ps
ps: /usr/bin/ps /usr/share/man/man1/ps.1.gz
[root ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
[root ~]# which ps
/usr/bin/ps
[root ~]# which python
/usr/bin/python
清除屏幕上显示的内容 - clear。
查看帮助文档 - man / info / —help / apropos。
[root@izwz97tbgo9lkabnat2lo8z ~]# ps --help
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
[root@izwz97tbgo9lkabnat2lo8z ~]# man ps
PS(1) User Commands PS(1)
NAME
ps - report a snapshot of the current processes.
SYNOPSIS
ps [options]
DESCRIPTION
...
查看系统和主机名 - uname / hostname。
[root@izwz97tbgo9lkabnat2lo8z ~]# uname
Linux
[root@izwz97tbgo9lkabnat2lo8z ~]# hostname
izwz97tbgo9lkabnat2lo8z
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
说明:
cat
是连接文件内容并打印到标准输出的命令,后面会讲到该命令;/etc
是Linux系统上的一个非常重要的目录,它保存了很多的配置文件;centos-release
是该目录下的一个文件,因为我自己使用的Linux发行版本是CentOS 7.6,因此这里会有一个这样的文件。时间和日期 - date / cal。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# date
Wed Jun 20 12:53:19 CST 2018
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cal
June 2018
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
[root@iZwz97tbgo9lkabnat2lo8Z ~]# cal 5 2017
May 2017
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
重启和关机 - reboot / shutdown。
[root ~]# shutdown -h +5
Shutdown scheduled for Sun 2019-05-26 19:34:27 CST, use 'shutdown -c' to cancel.
[root ~]#
Broadcast message from root (Sun 2019-05-26 19:29:27 CST):
The system is going down for power-off at Sun 2019-05-26 19:34:27 CST!
[root ~]# shutdown -c
Broadcast message from root (Sun 2019-05-26 19:30:22 CST):
The system shutdown has been cancelled at Sun 2019-05-26 19:31:22 CST!
[root ~]# shutdown -r 23:58
Shutdown scheduled for Sun 2019-05-26 23:58:00 CST, use 'shutdown -c' to cancel.
[root ~]# shutdown -c
Broadcast message from root (Sun 2019-05-26 19:31:06 CST):
The system shutdown has been cancelled at Sun 2019-05-26 19:32:06 CST!
说明:在执行
shutdown
命令时会向登录系统的用户发出警告,可以在命令后面跟上警告消息来替换默认的警告消息,也可以在-h
参数后通过now
来表示立刻关机。退出登录 - exit / logout。
查看历史命令 - history。
[root@iZwz97tbgo9lkabnat2lo8Z ~]# history
...
452 ls
453 cd Python-3.6.5/
454 clear
455 history
[root@iZwz97tbgo9lkabnat2lo8Z ~]# !454
说明:查看到历史命令之后,可以用
!历史命令编号
来重新执行该命令;通过history -c
可以清除历史命令。