1.获取命令帮助

Linux中的命令按可分类shell内嵌命令外部命令,获取命令帮助信息前需要区分命令类型。

1.1 type - 查看命令类型
[root@VM_0_171_centos ~]# type echo
echo 是 shell 内嵌
[root@VM_0_171_centos ~]# type pwd
pwd 是 shell 内嵌
[root@VM_0_171_centos ~]# type cd
cd 是 shell 内嵌
[root@VM_0_171_centos ~]# type ls
ls 是 `ls --color=auto' 的别名
[root@VM_0_171_centos ~]# type man
man 是 /usr/bin/man
[root@VM_0_171_centos ~]# type whatis
whatis 是 /usr/bin/whatis
[root@VM_0_171_centos ~]# type whereis
whereis 是 /usr/bin/whereis
[root@VM_0_171_centos ~]#
1.2 help 内嵌命令 - 查看shell内嵌命令帮助
[root@VM_0_171_centos ~]# help echo
echo: echo [-neE] [参数 ...]
    将参数写到标准输出。

    在标准输出上显示 ARG 参数后跟一个换行。

    选项:
      -n	不要追加换行
      -e	启用下列反斜杠转义的解释
      -E	显式地抑制对于反斜杠转义的解释

    `echo' 对下列反斜杠字符进行转义:
      \a	警告(响铃)
      \b	退格
      \c	抑制更多的输出
      \e	转义字符
      \f	格式提供
      \n	换行
      \r	回车
      \t	横向制表符
      \v	纵向制表符
      \\	反斜杠
      \0nnn	以 NNN (八进制)为 ASCII 码的字符。 NNN 可以是
    	0到3个八进制数字
      \xHH	以 HH (十六进制)为值的八比特字符。HH可以是
    	一个或两个十六进制数字

    退出状态:
    返回成功除非有写错误发生。
[root@VM_0_171_centos ~]#
1.3 whatis - 显示手册页描述

通常用于辅助man命令,确定帮助手册章节

[root@VM_0_171_centos ~]# whatis whatis
whatis (1)           - display manual page descriptions
[root@VM_0_171_centos ~]#
1.4 man [章节] 外部命令 - 查看外部命令帮助

man命令用来查看外部程序的帮助,有时需要配合whatis使用,因为man命令的帮助文档会按章节划分,各章节分别存放不同内容的帮助信息

帮助信息章节划分

1.用户命令
2.系统调用
3.C库调用
4.设备文件及特殊文件
5.文件格式(配置文件格式)
6.游戏使用帮助
7.杂项
8.管理工具及守护进程

[root@VM_0_171_centos ~]# man man
MAN(1)                        Manual pager utils                        MAN(1)

NAME
       man - an interface to the on-line reference manuals

SYNOPSIS
       man  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R encoding] [-L
       locale] [-m system[,...]] [-M path] [-S list]  [-e  extension]  [-i|-I]
       [--regex|--wildcard]   [--names-only]  [-a]  [-u]  [--no-subpages]  [-P
       pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justifi‐
       cation]  [-p  string]  [-t]  [-T[device]]  [-H[browser]] [-X[dpi]] [-Z]
       [[section] page ...] ...
       man -k [apropos options] regexp ...
       man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
       man -f [whatis options] page ...
       man -l [-C file] [-d] [-D] [--warnings[=warnings]]  [-R  encoding]  [-L
       locale]  [-P  pager]  [-r  prompt]  [-7] [-E encoding] [-p string] [-t]
       [-T[device]] [-H[browser]] [-X[dpi]] [-Z] file ...
       man -w|-W [-C file] [-d] [-D] page ...
       man -c [-C file] [-d] [-D] page ...
       man [-?V]

DESCRIPTION
       man is the system's manual pager. Each page argument given  to  man  is
 Manual page man(1) line 1 (press h for help or q to quit)

手册页常用操作

j | Enter : 向下翻一行
k : 向上翻一行
d : 向下翻半屏
u : 向上翻半屏
Space : 向下翻一屏
b : 向上翻一屏
G : 跳转至最后一行
nG : 跳转至第n行
/关键字 : 从上向下查找关键字(n:定位到下一个 ,N:定位到上一个)
?关键字 : 从下向上查找关键字

2.显示一行文本 echo

SYNOPSIS

echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION

OPTIONS

-n do not output the trailing newline(不输出尾随行)
-e enable interpretation of backslash escapes(启用转义)
-E disable interpretation of backslash escapes (default) (禁用转义)
--help 显示帮助
--version 显示版本信息

EXAMPLES

[root@VM_0_171_centos ~]# echo "hello world"
hello world
[root@VM_0_171_centos ~]# echo $SHELL
/bin/bash
[root@VM_0_171_centos ~]# echo -e "hello\tworld\nlinux"
hello	world
linux
[root@VM_0_171_centos ~]#

3.日期时间相关

3.1 date - print or set the system date and time 打印或设置系统日期和时间

SYNOPSIS

date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

OPTIONS

-R, --rfc-2822    output date and time in RFC 2822 format.  Example: Mon, 07 Aug 2006 12:34:56 -0600
-s, --set=STRING    set time described by STRING (用字符串设置时间,而非使用MMDDhhmm[[CC]YY][.ss])

EXAMPLES

date命令显示日期、时间

[root@VM_0_171_centos ~]# date
2017年 04月 03日 星期一 17:32:35 CST
[root@VM_0_171_centos ~]# date -R
Mon, 03 Apr 2017 17:32:41 +0800
[root@VM_0_171_centos ~]# date "+%Y-%m-%d %H:%M:%S.%N"
2017-04-03 17:33:21.620667704
[root@VM_0_171_centos ~]# date +%s
1491212010
[root@VM_0_171_centos ~]# date +%X
17时33分38秒
[root@VM_0_171_centos ~]# date +%x
2017年04月03日
[root@VM_0_171_centos ~]#

date命令设置日期、时间

[root@VM_0_171_centos ~]# date -s "2016-04-03 17:36:30"
2016年 04月 03日 星期日 17:36:30 CST
[root@VM_0_171_centos ~]# date 040317382017.20
2017年 04月 03日 星期一 17:38:20 CST
[root@VM_0_171_centos ~]#
3.2 hwclock,clock - query or set the hardware clock (RTC) 查询或设置硬件时钟

SYNOPSIS

hwclock [function] [option...]

FUNCTIONS

-s, --hctosys    以硬件为准,把系统调整为与硬件时间相同
-w, --systohc    以系统为准,把硬件时间调整为与系统时钟相同
3.3 cal - display a calendar 显示日历

SYNOPSIS

cal [options] [[[day] month] year]

OPTIONS

-1, --one    Display single month output.  (This is the default.)
-3, --three    Display prev/current/next month output.
-s, --sunday    Display Sunday as the first day of the week.
-m, --monday    Display Monday as the first day of the week.
-j, --julian    Display Julian dates (days one-based, numbered from January 1).
-y, --year    Display a calendar for the current year.

EXAMPLES

[root@VM_0_171_centos ~]# cal
      四月 2017
日 一 二 三 四 五 六
                   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@VM_0_171_centos ~]# cal -m
      四月 2017
一 二 三 四 五 六 日
                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@VM_0_171_centos ~]# cal -3
      三月 2017             四月 2017             五月 2017
日 一 二 三 四 五 六  日 一 二 三 四 五 六  日 一 二 三 四 五 六
          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
[root@VM_0_171_centos ~]# cal -y
                               2017

        一月                   二月                   三月
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
 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

        四月                   五月                   六月
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                   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
        七月                   八月                   九月
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                   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
        十月                  十一月                 十二月
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
 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

[root@VM_0_171_centos ~]#

3.停止、关机、重启

远程操作一般而言禁止关机,只能重启,否则无法开机(本地机房或者云服务器除外,但对服务器操作而言,重启而非关机是一个好的习惯)

3.1 halt, poweroff, reboot - Halt, power-off or reboot the machine

SYNOPSIS

halt [OPTIONS...]
poweroff [OPTIONS...]
reboot [OPTIONS...]

OPTIONS

--halt
Halt the machine, regardless of which one of the three commands is invoked.

-p, --poweroff
Power-off the machine, regardless of which one of the three commands is invoked.

--reboot
Reboot the machine, regardless of which one of the three commands is invoked.

-f, --force    
Force immediate halt, power-off, reboot. Do not contact the init system.

-w, --wtmp-only
Only write wtmp shutdown entry, do not actually halt, power-off,reboot.

-d, --no-wtmp    
Do not write wtmp shutdown entry.

--no-wall    
Do not send wall message before halt, power-off, reboot.

halt、poweroff、reboot这3个命令比较简单,而且可以被shutdown替代

3.2 shutdown - Halt, power-off or reboot the machine

SYNOPSIS

shutdown [OPTIONS...] [TIME] [WALL...]

OPTIONS

-H, --halt
Halt the machine.

-P, --poweroff
Power-off the machine (the default).

-r, --reboot
Reboot the machine.

-h
Equivalent to --poweroff, unless --halt is specified.

-k
Do not halt, power-off, reboot, just write wall message.

--no-wall
Do not send wall message before halt, power-off, reboot.

-c
Cancel a pending shutdown. This may be used cancel the effect of an invocation of shutdown with a time argument that is not "+0" or "now".

EXAMPLES
shutdown这个命令不难,执行结果比较特殊,就不做演示了。