bash手册

man命令

man命令用来访问存储在Linux系统上的手册页面。在想要查找的工具的名称前面输入man命令,就可以找到那个工具相应的手册条目。

man man

窍门:bash手册甚至包含了一份有关其自身的参考信息。输入man man来查看与手册页相关的手册页。

根据上面的提示,我在控制台终端输入这行代码:

root@huangzihan:/# man man

然后它弹出这样一个页面:

MAN(1)                                                    Manual pager utils                                                   MAN(1)

NAME
man - an interface to the system reference manuals SYNOPSIS
man [man options] [[section] page ...] ...
man -k [apropos options] regexp ...
man -K [man options] [section] term ...
man -f [whatis options] page ...
man -l [man options] file ...
man -w|-W [man options] page ... DESCRIPTION
man is the system's manual pager. Each page argument given to man is normally the name of a program, utility or function.
The manual page associated with each of these arguments is then found and displayed. A section, if provided, will direct man
to look only in that section of the manual. The default action is to search in all of the available sections following a pre-
defined order (see DEFAULTS), and to show only the first page found, even if page exists in several sections.
...
...
...

如果我们想退出这个页面,直接按q键就可以。然后我又查了我平时用的那条ls指令,整个过程代码如下:

root@huangzihan:/# man ls

LS(1)                                                       User Commands                                                       LS(1)

NAME
ls - list directory contents SYNOPSIS
ls [OPTION]... [FILE]... DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor
--sort is specified. Mandatory arguments to long options are mandatory for short options too. -a, --all
do not ignore entries starting with . ...
...
...

窍门:如果你是新接触bash shell,可能一开始会觉得手册页面并不太用。但是如果养成了阅读手册的习惯,尤其是阅读第一段或是DESCRIPTION部分的前两段,最终你会学到各种技术行话,手册页也会变得越来越有用。

分页程序(page)

当使用man命令查看命令手册的时候,这些手册页是由分页程序(page)来显示的。分页程序是一种实用工具,能够逐页显示文本。可以通过点击空格键进行翻页,或是使用回车键逐行查看。另外还可以使用箭头键向前向后滚动手册页的内容(假设你用的终端仿真软件包支持箭头键功能)。

在分页程序最下面的一行有这样一条语句:

 Manual page ls(1) line 1/218 15% (press h for help or q to quit)

当我们使用回车键和箭头键向前向后的时候,这句话在中的1/218的1不断地增加。

读完了手册页,可以点击q键退出。退出手册页之后,你会重新获得shell CLI提示符,这表示shell正在等待接受下一条命令。

手册页将与命令相关的信息分成了不同的节。每一节惯用的命名标准如表Linux手册页惯用的节名

Linux手册页惯用的节名

描述
Name 显示命令名和一段简短的描述
Synopsis 命令的语法
Confi guration 命令配置信息
Description 命令的一般性描述
Options 命令选项描述
Exit Status 命令的退出状态指示
Return Value 命令的返回值
Errors 命令的错误消息
Environment 描述所使用的环境变量
Files 命令用到的文件
Versions 命令的版本信息
Conforming To 命令所遵从的标准
Notes 其他所遵从的标准
Bugs 提供提交bug的途径
Example 展示命令的用法
Authors 命令开发人员的信息
Copyright 命令源代码的版权状况
See Also 与该命令类型的其他命令

窍门:如果不记得命令名怎么办?可以使用关键字搜索手册页。语法是:man -k 关键字。例如,要查找与终端相关的命令,可以输入man -k terminal。

除了对节按照惯例进行命名,手册页还有对应的内容区域。每个内容区域都分配了一个数字,从1开始,一直到9,如下表Linux手册页的内容区域

Linux手册页的内容区域

区域号 所涵盖的内容
1 可执行程序或shell命令
2 系统调用
3 库调用
4 特殊文件
5 文件格式与约定
6 游戏
7 概览、约定及杂项
8 超级用户和系统管理员命令
9 内核例程
查看命令在Linux手册页中的区域

man工具通常提供的是命令所对应的最低编号的内容。

当我在命令行输入man ls,在弹出来的分页程序中的第一行和最后一行,发现这两条语句中的LS和ls后面的括号有一个数字:(1)。这表示所显示的手册页来自内容区域1(可执行程序或shell命令)

LS(1)                  User Commands                         LS(1)
Manual page ls(1) line 1/218 15% (press h for help or q to quit)

一个命令偶尔会在多个内容区域都有对应的手册页。比如说,有个叫作hostname的命令。手册页中既包括该命令的相关信息,也包括对系统主机名的概述。想要查看所需要的页面,可以输入man section# topic。对手册页的第一部分而言,就是输入man 1 hostname。对于手册页中的第7部分,就是输入man 7 hostname

我根据上面的提示分别打开了hostname的第1部分和第7部分,部分代码如下:

root@huangzihan:/# man 1 hostname
HOSTNAME(1) Linux Programmer's Manual HOSTNAME(1) NAME
hostname - show or set the system's host name
domainname - show or set the system's NIS/YP domain name
ypdomainname - show or set the system's NIS/YP domain name
nisdomainname - show or set the system's NIS/YP domain name
dnsdomainname - show the system's DNS domain name ...
...
...
root@huangzihan:/# man 7 hostname
HOSTNAME(7) Linux Programmer's Manual HOSTNAME(7) NAME
hostname - hostname resolution description
...
...
...

你也可以只看各部分内容的简介:输入man 1 intro阅读第1部分,输入man 2 intro阅读第2部分,输入man 3 intro阅读第3部分,等等。

根据上面的提示,我在提示符#后面分别输入man 1 introman 7 intro,控制台终端的输出如下:

root@huangzihan:/# man 1 intro
INTRO(1) Linux User's Manual INTRO(1) NAME
intro - introduction to user commands
...
...
...
root@huangzihan:/# man 7 intro
INTRO(7) Linux Programmer's Manual INTRO(7) NAME
intro - introduction to overview and miscellany section
...
...
...

当我想查看ls的第2部分、第3部分、第4部分,在shell提示符#后面分别输入man 2 lsman 3 lsman 4 ls,但是因为ls这条命令没有这三部分,所以控制台终端输出是这样的:

root@huangzihan:/# man 2 ls
No manual entry for ls in section 2
root@huangzihan:/# man 3 ls
No manual entry for ls in section 3
root@huangzihan:/# man 4 ls
No manual entry for ls in section 4

info页面

手册页不是唯一的参考资料。还有另一种叫作info页面的信息。可以输入info info来了解info页面的相关内容。

根据上面的提示,我在提示符#后面输入info info,控制台终端的输出如下:

Next: Stand-alone Info,  Up: (dir)

Stand-alone GNU Info
******************** This documentation describes the stand-alone Info reader which you can
use to read Info documentation.
...
...
...

如果想查看ls的info页面,我们可以把上面那条命令改为info ls,对应的控制台的输出为:

root@huangzihan:/# info ls
Next: dir invocation, Up: Directory listing 10.1 ‘ls’: List directory contents
================================== The ‘ls’ program lists information about files (of any type, including
directories). Options and file arguments can be intermixed arbitrarily,
as usual.
...
...
...

help帮助

另外,大多数命令都可以接受-help--help选项。例如你可以输入hostname -help来查看帮助。关于帮助的更多信息,可以输入help help。(看出这里面的门道没?)

根据上面的提示,我在shell提示符#后面输入help help,对应的控制台终端输出是这样的:

root@huangzihan:/# help help
help: help [-dms] [pattern ...]
Display information about builtin commands. Displays brief summaries of builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
otherwise the list of help topics is printed. ...
...
...

如果想查看ls命名,可以在shell提示符#后面输入ls --help,这个查看ls的命令只有这个是对的,中途我还输错了几次,整个过程代码是这样的:

root@huangzihan:/# ls -help
ls: invalid option -- 'e'
Try 'ls --help' for more information.
root@huangzihan:/# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
...
...
...

bash手册的更多相关文章

  1. bash手册 之重定向原理与实现

    http://www.gnu.org/software/bash/manual/bashref.html#Redirections http://www.cnblogs.com/weidagang20 ...

  2. bash帮助文档简单学习;bash手册翻译

    关于bash的四种工作方式的不同,可以参考:http://feihu.me/blog/2014/env-problem-when-ssh-executing-command-on-remote/,但是 ...

  3. Linux编程 3 (初识bash shell与man查看手册)

    一.初识bash shell 1.1 启动 shell   GNU bash shell 能提供对Linux系统的交互式访问.通常是在用户登录终端时启动,登录时系统启动shell依赖于用户账户的配置. ...

  4. 基本bash命令

    bash手册 输入man命令可以访问存储在linux系统上的手册页面.  如果不记得命令名,可以使用关键字搜索手册.语法是man -k 关键字.  手册被分为了不同的内容区域.man工具提供的是命 ...

  5. bash脚本编程之二 字符串测试及for循环

    shell中大量的测试和比较选项而困惑呢? 这个技巧可以帮助您解密不同类型的文件.算术和字符串测试,这样您就能够知道什么时候使用 test. [ ]. [[ ]].(( )) 或 if-then-el ...

  6. Linux命令行–基本的bash shell命令

    启动shell: /etc/passwd:包含系统用户账户列表以及每个用户的基本配置信息 每个条目有七个字段,每个字段用冒号隔开 用户名 用户密码 用户的系统UID 用户的系统GID 用户的全名 用户 ...

  7. 【转】Linux 技巧: Bash 参数和参数扩展

    重点看下清单7 现在,很多 Linux® 和 UNIX® 系统上都有 bash shell,它是 Linux 上常见的默认 shell.通过本文,您将了解到如何在 bash 脚本中处理参数和选项,以及 ...

  8. 【深夜急报,Win10下的Linux子系统之Bash】

    [在Windows下进行的编程人员,你真的需要学习下Linux] 手册:<Linux 命令手册(特洛伊版2.0)> 链接: https://pan.baidu.com/s/1skrVSvV ...

  9. 了解基本的bash shell命令

    本节内容主要介绍如何使用bash shell提供的基本命令处理Linux文件和目录: 1.启动shell shell是一个可以交互访问的Linux系统程序,它的运行与普通程序相同,系统启动的shell ...

随机推荐

  1. ES6中class的继承

    extends 子类的继承 super(); 调用父类的构造方法,只能在子类中执行 继承可以让子类获得父类的方法 属性,可以扩充 增加新的方法 属性等 父类(基类)--被继承的类 子类--继承后的类 ...

  2. elsa core—3.elsa 服务

    在本快速入门中,我们将介绍一个用于设置Elsa Server的最小ASP.NET Core应用程序.我们还将安装一些更常用的activities(活动),如Timer.Cron和sendmail,以能 ...

  3. 五分钟搞懂MySQL索引下推

    大家好,我是老三,今天分享一个小知识点--索引下推. 如果你在面试中,听到MySQL5.6"."索引优化" 之类的词语,你就要立马get到,这个问的是"索引下推 ...

  4. Vue+element基本增删改查

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  5. try catch处理流的异常

    1.try catch处理异常 try{} catch(Exception e){} finally{ 必然执行的代码,一般是释放资源 } 2.流使用try catch处理异常 其中,变量作用域只在当 ...

  6. Sonarqube C# 配置资料整理

    c#配置方式: http://www.cnblogs.com/CoderAyu/p/9416376.html http://www.cnblogs.com/jingridong/p/6513884.h ...

  7. 1004. 最大连续1的个数 III

    1004. 最大连续1的个数 III 给定一个由若干 0 和 1 组成的数组 A,我们最多可以将 K 个值从 0 变成 1 . 返回仅包含 1 的最长(连续)子数组的长度. 示例 1: 输入:A = ...

  8. DEDEcms手机网站添加详情内页上一页/下一页的翻页功能

    修改文件include/arc.archives.class.php文件. 1.搜索 function GetPreNext($gtype='') 2.将这个函数的所有内容替换为 function G ...

  9. django使用restframework序列化查询集合(querryset)

    第一: pip install djangorestframework 第二: 在setting.py文件中的app添加名为: 'rest_framework', 第三:再项目的APP下面新建名为(可 ...

  10. windows kubectl 远程操作k8s

    在windows 电脑上配置kubectl远程操作kubernetes 一.下载windows版的kubectl可执行文件 下载地址 二.创建.kube 建议使用git bash cd ~ mkdir ...