遇到陌生的 Linux 命令怎么办

1、whatis

whatis 命令用于描述一个命令执行什么功能。

whatis <cmd>

示例:

$ whatis bash
bash (1)             - GNU Bourne-Again SHell

2、whereis

whereis 命令用于查找二进制文件、源文件和 man 手册页的路径。

whereis <cmd>

示例:

$ whereis bash
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz

3、which

which 命令用于查看并显示指定命令的绝对路径,可用此命令检查系统是否存在某个命令,以及该命令所在的位置。

which <cmd>

示例:

$ which bash
/bin/bash

4、type

type 命令用于查看命令的类型,比如命令是内建的还是外部的。

type <cmd>

示例

$ type bash
bash 是 /bin/bash

$ type cd
cd 是 shell 内建

$ type ls
ls 是 `ls --color=auto' 的别名

5、command

command 命令用于执行一个简单命令或者显示命令的相关信息。

command [-pVv] <cmd>

示例:

$ command -v bash
/bin/bash

6、help 和 --help

  • help 命令只能用于内部命令,不能用于外部命令。
  • --help 用于外部命令,但并非所有命令都支持。
help <cmd>
<cmd> --help

7、man

通常来说,man 得到的信息比 help 要多,且没有内建和外部命令的区分。因为 man 工具是显示系统手册页中的内容,也就是一本电子版的字典,其内容大多数是对命令的解释,另外还有一些相关的描述。

man [1-9] <cmd>

比如执行 man bash,会显示如下内容:

BASH(1)                 General Commands Manual                  BASH(1)

NAME
       bash - GNU Bourne-Again SHell

SYNOPSIS
       bash [options] [command_string | file]

......

第一行的 “BASH(1)”,“BASH” 表示手册名称,“(1)” 表示该手册位于第一章节。而 man 手册一共有下面 9 个章节,不同章节包含不同类型的内容。

  1. Standard commands,可执行程序或 shell 命令;
  2. System calls,系统调用(内核提供的函数);
  3. Library functions,库调用(程序库中的函数);
  4. Special Devices,特殊文件(通常位于 /dev);
  5. File formats,文件格式和规范,如 /etc/passwd;
  6. Games and toys,游戏和娱乐;
  7. Miscellaneous,杂项(包括宏包和规范,如 man(7)groff(7));
  8. Adminstrative commands,系统管理命令(通常只针对 root 用户);
  9. 内核例程。

注意: 如果指定了章节,man 将只在手册的指定章节搜索。默认将按预定的顺序查找所有可用的章节,默认查找顺序是 “1 n l 8 3 2 3posix 3pm 3perl 5 4 9 6 7”(除非被 /etc/manpath.config 中的 SECTION 指令覆盖)。并且 man 只显示找到的第一个页,即使多个章节中都有这个页面。

比如,mkdir 命令,执行 man mkdir 时显示如下内容:

MKDIR(1)                   User Commands                   MKDIR(1)

NAME
       mkdir - make directories

SYNOPSIS
       mkdir [OPTION]... DIRECTORY...

......

执行 man 2 mkdir 时显示如下内容:

MKDIR(2)                  Linux Programmer's Manual                 MKDIR(2)

NAME
       mkdir, mkdirat - create a directory

SYNOPSIS
       #include <sys/stat.h>
       #include <sys/types.h>

       int mkdir(const char *pathname, mode_t mode);
......

8、info

man 和 info 就像两个集合,它们有一个交集部分,但与 man 相比,info 可显示更完整的 GNU 工具信息。这是因为,info 来自 GNU 项目,是 GNU 的超文本帮助系统,因此能够更完整地显示出 GNU 信息。

info <cmd>

比如,执行 info info,显示如下内容:

File: dir,      Node: Top,      This is the top of the INFO tree.

This is the Info main menu (aka directory node).
A few useful Info commands:

  'q' quits;
  '?' lists all Info commands;
  'h' starts the Info tutorial;
  'mTexinfo RET' visits the Texinfo manual, etc.

* Menu:

Archiving
* Shar utilities: (sharutils).  Shell archiver, uuencode/uudecode.

Basics
* Common options: (coreutils)Common options.
* Coreutils: (coreutils).       Core GNU (file, text, shell) utilities.
......

与 man 页面只用一页来显示内容的方式不同,info 页面把内容组织成多个区段(称为节点),每个区段也可能包含子区段(称为子节点)。因此在浏览 info 页面内容时,还需要学会如何在节点和子节点之间切换。

发布了299 篇原创文章 · 获赞 1219 · 访问量 159万+

猜你喜欢

转载自blog.csdn.net/luckydarcy/article/details/103129772