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. Focal Loss(RetinaNet)笔记 一种减小类别不平衡影响的方法

    Paper: https://arxiv.org/abs/1708.02002 还参考了:https://www.jianshu.com/p/8e501a159b28 其中p是预测属于某类的概率.

  2. [考试总结]noip模拟45

    真开心,挂没了.. 考完:"你们怎么第二题打了这么点分,明明一个爆搜就有65pts!!!怎么跟别人打?!" 然后我看了看我的爆搜,30pts. 然后认为自己打爆了... 我又想为什 ...

  3. Python - 头部解析

    背景 写 python 的时候,基本都要加两个头部注释,这到底有啥用呢? #!usr/bin/env python # -*- coding:utf-8 _*- print("hello-w ...

  4. 【MyBatis】几种批量插入效率的比较

    批处理数据主要有三种方式: 反复执行单条插入语句 foreach 拼接 sql 批处理 一.前期准备 基于Spring Boot + Mysql,同时为了省略get/set,使用了lombok,详见p ...

  5. liquibase新增字段注释导致表格注释同时变更bug记录

    liquibase是一个用于数据库变更跟踪.版本管理和自动部署的开源工具.它的使用方式方法可以参考官方文档或者其他人的博客,这里不做过多介绍. 1. 问题复现 在使用过程中发现了一个版本bug.这个b ...

  6. python字典时间日期

    字典时间日期 学习完本篇,你将会深入掌握 字典操作. 1.如何新建一个字典 2.如何正序以及反序访问字典 3.如何更新字典元素 4.如何删除字典 日期时间操作 1.如何打印一个2021-9-20 17 ...

  7. C#中List是链表吗?为什么可以通过下标访问

    使用C#的同学对List应该并不陌生,我们不需要初始化它的大小,并且可以方便的使用Add和Remove方法执行添加和删除操作,但却可以使用下标来访问它的数据,它是我们常说的链表吗?     List& ...

  8. git实战-linux定时监控github更新状态(二)

    系列文章 git介绍-常用操作(一)✓ git实战-linux定时监控github更新状态(二)✓ 本文主要内容 如何查看github的本地仓库和远程仓库的同步情况 linux服务器定时监控githu ...

  9. 重学VUE——vue 常用指令有哪些?

    一.什么是指令? 在 vue 中,指令以 v- 开头,是一种特殊的自定义行间属性.指令属性的预期值是一个表达式,指令的职责就是:表达式的值改变时,相应地将某些行为应用到DOM上.只有v-for是一个类 ...

  10. PHP怎么遍历对象?

    对于php来说,foreach是非常方便好用的一个语法,几乎对于每一个PHPer它都是日常接触最多的请求之一.那么对象是否能通过foreach来遍历呢? 答案是肯定的,但是有个条件,那就是对象的遍历只 ...