【跟小嘉学 Linux 系统架构与开发】三、如何查看帮助文档

系列文章目录

【跟小嘉学 Linux 系统架构与开发】一、学习环境的准备与Linux系统介绍
【跟小嘉学 Linux 系统架构与开发】二、Linux发型版介绍与基础常用命令介绍
【跟小嘉学 Linux 系统架构与开发】三、如何查看帮助文档

前言

前面我们讲解了基础的日历、日期与时间、计算器等命令,以及常用的快捷键操作,我们这一节详细讲解,如何查看Linux的手册、文档、帮助信息等信息。

参考资料
《鸟哥的Linux私房菜繁体版》
《鸟哥的Linux私房菜简体版》


一、 命令的 --help 帮助说明

几乎 Linux 上的命令,在开发的时候,开发者就会将命令的语法与参数写入到指令操作手册上了,你只需要使用 --help这个选项,就能够将该命令的用法一个大致的理解。

我们拿最熟悉的 date 的命令来查看

[vagrant@10 ~]$ 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/>
Report date translation bugs to <http://translationproject.org/team/>
For complete documentation, run: info coreutils 'date invocation'
  • Usage: 表明 date 命令的语法格式
  • 接下来就是 [OPTION] 选项的内容
  • 在接下来就是格式化控制台输出的格式序列

二、man page

2.1、man page 介绍

date --help 并没有详细告诉你 STRING 是什么东西,我们如果想要清清楚楚的知道该指令的用法。我们可以找 man 命令(manual).

DATE(1)                                              User Commands                                             DATE(1)

NAME
       date - print or set the system date and time

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

DESCRIPTION
       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',
 Manual page date(1) line 1 (press h for help or q to quit)
  • DATE(1):括号中的1 代表 我们指令的内容,这个编码从1-9有9个含义
    • 1 :用户交互的命令,例如 ls、cp、man、grep等
    • 2: 系统调用和内核函数
    • 3:包含库函数和标准c函数
    • 4:包含配置文件和设备文件
    • 5:包含配置文件格式和协议
    • 6:包含游戏和演示程序
    • 7:包含惯例、协议、文件格式等
    • 8:包含系统管理命令
    • 9:和内核有关的文件
  • NAME:命令的完整名称和命令用法
  • SYNPSIS:命令的基本语法
  • DESCRIPTION:详细说明语法中的选项参数的用法
  • ENVIRONMENT:与这个命令相关的环境参数
  • EXAMPLES:使用示例
  • DATE STRING:日期的格式说明
  • AUTHOR:命令的作者
  • COPYRIGHT 版权声明
  • SEE ALSO:还可以查找的文档

2.2、man page 快捷

快捷键表格

按键作用
空格键向下翻页
[Page Down]向下翻一頁
[Page Up]向上翻一頁
[Home]去到第一頁
[End]去到最後一頁
/string向『下』查找 string 字符串,
?string向『上』查找 string 這個字串
n, N利用 / 或 ? 來查找字串時,可以用 n 來繼續下一個查找 (不论是 / 或 ?) ,可以利用 N 來進行『反向』查找。
q結束這次的 man page

2.3、man page 资料位置

不同的发行版存放的路径可能有点差异,不过通常都是 在 /usr/share/man 目录,我们可以man 的搜索路径来改善目录的问题

修改 /etc/man_db.confman.confmanpath.confman.config,关于 man 命令的详细信息,我们也可以通过 man man 命令来查询

2.4、man 命令用法

2.4.1、查看与 man 命令有关的文档

[vagrant@10 ~]$ man -f man
man (1)              - an interface to the on-line reference manuals
man (1p)             - display system documentation
man (7)              - macros to format man pages

man -f 命令也可以使用 whatis 来替代

[vagrant@10 ~]$ whatis man
whatis: can't set the locale; make sure $LC_* and $LANG are correct
man (1)              - an interface to the on-line reference manuals
man (1p)             - display system documentation
man (7)              - macros to format man pages

2.4.2、查看对应类型的 man 命令的相关资料

man 1 man
man 7 man

2.4.3、查找关键字有关的命令

man -k man

man -k 命令也可以使用 apropos 命令来替代

apropos man

2.4.3、mandb

whatisapropos 命令要能使用,必须建立 whatis 资料库才可以,可以在 root 账号下使用 下面命令来生成

[vagrant@10 ~]$ su -  # 切换到 root 账号 - 表示环境变量也切换
Password: 
Last login: Sun Mar 31 18:00:45 UTC 2024 on pts/0
[root@10 ~]# mandb
Purging old database entries in /usr/share/man...
Processing manual pages under /usr/share/man...
Purging old database entries in /usr/share/man/ru...
Processing manual pages under /usr/share/man/ru...
Purging old database entries in /usr/share/man/en...
Processing manual pages under /usr/share/man/en...
Purging old database entries in /usr/local/share/man...
Processing manual pages under /usr/local/share/man...
0 man subdirectories contained newer manual pages.
0 manual pages were added.
0 stray cats were added.
0 old database entries were purged.

三、info

3.1、info 命令介绍

info 命令 和 man 命令到用法差不多,就是用来查询命令的用法或者文件的格式,info page 是将文件拆成一个个段落,每个段落有自己的页面来编写,并且每个页面都有类似的超链接来跳到不同的页面。

info 命令的文件是存放在 /usr/share/info 目录之中.

[root@10 ~]# info info

File: info.info,  Node: Top,  Next: Getting Started,  Up: (dir)

Info: An Introduction
*********************

The GNU Project distributes most of its on-line manuals in the "Info
format", which you read using an "Info reader".  You are probably using
an Info reader to read this now.

   There are two primary Info readers: 'info', a stand-alone program
designed just to read Info files (*note What is Info?: (info-stnd)Top.),
and the 'info' package in GNU Emacs, a general-purpose editor.  At
present, only the Emacs reader supports using a mouse.

   If you are new to the Info reader and want to learn how to use it,
type the command 'h' now.  It brings you to a programmed instruction
sequence.

   To read about advanced Info commands, type 'n' twice.  This brings
you to 'Advanced Info Commands', skipping over the 'Getting Started'
chapter.
--zz-Info: (info.info.gz)Top, 52 lines --Top------------------------------------------------------------------------------
No `Prev' or `Up' for this node within this document.

  • File:代表info page 的资料来自 info.info 这个文件所提供
  • Node:代表目前这个页面属于Top节点,意思是 info.info 内容有很多,Top只是其中一部分内容
  • Next:下一个节点的名称为:Getting Started,你也可以按 N 跳到下一个节点;
  • Up:回到上一层的节点,你也可以按 U 来回到上一层
  • Prev:前一个节点,但是TOP是第一个节点,所以上面没有前一个节点的内容

3.2、快捷键

按键功能
空格键向下翻一页
[Page Down]向下翻一页
[Page Up]向上翻一页
[tab]在 node 之间移动,有 node 的地方,通常会以 * 显示。
[Enter]当光标在 node 上面时,按下 Enter 可以进入该 node
b移动光标到该info 当中的第一个 node 处
e移动光标到该info 当中的最后一个 node 处
n前往下一个 node 处
p前往上一个 node 处
u向上移动一层
s(/)在 info page 当中进行搜索
h, ?显示帮助菜单
q結束这次的 info page

四、其他有用的文件(documents)

一般而言,命令或软件开发者都会将自己的命令或软件的说明制作成文档,但是并不是所有的命令或软件都有。

这些文件一般都存放在 /usr/share/doc

例如

/usr/share/doc/grub2-tools-2.02

五、正确的关机方法

关机的时候要注意几件事

  • 观察系统的使用状态:whonetstat -aps -aux
  • 通知用户关机的:shutdown
  • 正确的关机和重启命令:shutdownreboot
  • 资料同步写入硬盘命令:sync
  • 关机:haltpoweroffreboot
  • 管理工具:initsystemctl
  • 28
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小嘉丶学长

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值