linux中最常用的帮助命令

仅个人想法,会持续不间断更新和改进。

Linux有好几个关于帮助的命令,可以让我们在不上网的情况下获取一些丰硕的信息。

唯一的要求就是英语好一些,唯二的情况就是不确定的情况下在此确认后再执行。

此man非man的意思

首先,这man是什么意思?

最开始很多人认为是不知道这个什么意思,找man呀。

其实man是manual的缩写,也就是手册的意思。

man命令提供了系统命令的详细帮助信息。

Linux提供了丰富的帮助手册,当你需要查看某个命令的参数时不必到处上网查找,只要man一下即可。这个也是每个程序员必备的功能,在没有网络的情况下,man能解决很多问题和疑惑。

看一下官方定义:

Man – format and display the on-line manual pages

man 的格式

如果要读懂并使用man,首先需要了解man命令输出的格式,下面的几个是比较常用且需要注意的:

同时也可以使用man man 查看man的使用方法。

章节含义
NAME命令名称及功能简要说明
SYNOPSIS用法说明,包括可用的选项
DESCRIPTION命令功能的详细说明,可能包括每一个选项的意义
OPTIONS每一选项的意义
EXAMPLES一些使用示例

man的操作

比如输入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 .
      -A, –almost-all             do not list implied . and ..
      –author             with -l, print the author of each file
      -b, –escape             print C-style escapes for nongraphic characters
      –block-size=SIZE             scale sizes by SIZE before printing them; e.g., ‘–block-size=M’ prints sizes in units of 1,048,576             bytes; see SIZE format below
      -B, –ignore-backups Manual page ls(1) line 1 (press h for help or q to quit)

此时可以通过空格键或者回车键来向后翻屏或者翻页,可以使用b或者k向前查看。

 查看关键词时可以使用:

/关键词    向后查找   n:下一个

?关键词   向前查找   N:前一个

可以通过q来退出。

ls后面还有一个(1),详细的解释可以参考《Linux 安装 man 帮助程序》

类似于whatis命令

man有个参数为-f,就是whatis的功能,比如:$ man -f ls cd file cat more lessls (1)               – list directory contentsls (1p)              – list directory contentscd (1)               – bash built-in commands, see bash(1)cd (1p)              – change the working directorycd (n)               – Change working directoryfile (1)             – determine file typefile (1p)            – determine file typefile (n)             – Manipulate file names and attributescat (1)              – concatenate files and print on the standard outputcat (1p)             – concatenate and print filesmore (1)             – file perusal filter for crt viewingmore (1p)            – display files on a page-by-page basisless (1)             – opposite of moreless (3pm)           – perl pragma to request less of something

与whatis命令完全一致

类似于apropos命令

man有个参数为-k,就是apropos的功能,比如:$ man -k  whoat.allow (5)         – determine who can submit jobs via at or batchat.deny (5)          – determine who can submit jobs via at or batchbtrfs-filesystem (8) – command group of btrfs that usually work on the whole filesystemdocker-trust-signer (1) – Manage entities who can sign Docker imagesipsec_newhostkey (8) – generate a new raw RSA authentication key for a hostipsec_showhostkey (8) – show host’s authentication keyw (1)                – Show who is logged on and what they are doing.who (1)              – show who is logged onwho (1p)             – display who is on the systemwhoami (1)           – print effective userid

与apropos命令完全一致

使用man的小技巧

如果遇到一个不熟悉或者完全不知道的命令,此时可以通过下面的3个步骤来了解:

  1. 首先用man -k command 查询所有类似帮助文件信息,或许有可能就能找到你需要的信息;
  2. 然后man -f command 查询以command开始的相关帮助信息列表
  3. man N command 通过直接定位N获得详细帮助信息

你是干什么的 whatis

其实整个命令已出现,你的脑海里面应该浮现的是:

What is your name?

如题所述,这个命令用于查询一个命令到底执行了什么功能,并将查询的结果输出出来,相当于man的一个选项-f

whatis的官方定义为:

whatis – display manual page descriptions

仅仅提供一个比较简单的命令描述.

使用方法也比较简单,如下:$ whatis [options] name

其中的name可以是Linux命令、系统调用、库函数、系统等等内容

以前面的命令为例,执行如下所示:$ whatis ls cd file cat more lessls (1)               – list directory contentsls (1p)              – list directory contentscd (1)               – bash built-in commands, see bash(1)cd (1p)              – change the working directorycd (n)               – Change working directoryfile (1)             – determine file typefile (1p)            – determine file typefile (n)             – Manipulate file names and attributescat (1)              – concatenate files and print on the standard outputcat (1p)             – concatenate and print filesmore (1)             – file perusal filter for crt viewingmore (1p)            – display files on a page-by-page basisless (1)             – opposite of moreless (3pm)           – perl pragma to request less of something

可以看到whatis是支持同时查询多个命令的

拓展

whatis可以通过-w-r以及-C等选项来设定通配符、正则表达式以及配置文件等等,不过最简单的还是简单查看一个命令的简单描述,其他的可以交给man来处理。

指定目录的定位 whereis

Linux whereis 命令用于定位查找一个命令的二进制、源文件或帮助文件。

不过这些文件一般是位于特定目录的。

其他的程序定位可以考虑使用locate命令。

官方的定义为:

whereis – locate the binary, source, and manual page files for a command

使用语法

使用语法如下:$ whereis [options] [-BMS directory… -f] name…

其他的选项可以为:

  • -b : 查找二进制文件
  • -m:查找手册
  • -s:查找源文件
  • -B <directory>  在设置的目录下查找二进制文件。
  • -M <directory>  在设置的目录下查找说明文件。
  • -S <directory>  在设置的目录下查找原始代码文件。 

实例

比如查找bash的位置,输入如下命令:$ whereis bashbash: /usr/bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz

可以看到,以上的输出信息从左至右分别为程序名、bash路径、bash的man帮助手册路径。

单独查找文件

可以通过不同的参数来查找不同的文件,如下:# 查找二进制文件$ whereis -b bashbash: /usr/bin/bash /etc/bash.bashrc
# 查找帮助文件$ whereis -m bashbash: /usr/share/man/man1/bash.1.gz
# 查找源文件$ whereis -s bashbash:

刚刚好合适的 apropos 命令

apropos的中文含义就是恰好的、合适的,奈何这个单词或者命令确实不好记,当然是可以扩充词汇量的。

什么时候会用到这个命令呢,先看看这个命令的定义。

apropos 命令的官方定义为:

search the manual page names and descriptions

意思很明显,如果我不记得命令或者不知道该用什么命令的时候,可以通过关键词来索引查找这些命令,比如我们想用linux绘制图像,但是不知道什么命令,测试可以使用:$ apropos plot
bno_plot (1) – generate interactive 3D plot of IO blocks and sizes gnuplot (1) – an interactive plotting program pbmtoplot (1) – convert a PBM image into a Unix ‘plot’ file

或许每个人的输出不同,这个主要取决于安装的软件包和索引的数据库。以上。

再来一个实例,这个应该大部分的都类似:$ apropos who
at.allow (5)         – determine who can submit jobs via at or batchat.deny (5)          – determine who can submit jobs via at or batchbtrfs-filesystem (8) – command group of btrfs that usually work on the whole filesystemdocker-trust-signer (1) – Manage entities who can sign Docker imagesipsec_newhostkey (8) – generate a new raw RSA authentication key for a hostipsec_showhostkey (8) – show host’s authentication keyw (1)                – Show who is logged on and what they are doing.who (1)              – show who is logged onwho (1p)             – display who is on the systemwhoami (1)           – print effective userid

这个命令平时用的不多,跟whatis类似,因为这些功能都被加到了包罗万象的man命令。

声明:文中观点不代表本站立场。本文传送门:https://eyangzhen.com/389183.html

(0)
联系我们
联系我们
分享本页
返回顶部