Linux info命令介绍
info命令是information的缩写,它用来查看Linux系统中的文档信息,也就是手册页(man pages)。info命令可以显示更详细、更结构化、更易于浏览的文档信息,而不是像man命令那样只显示纯文本的格式。info命令还可以显示一些man命令无法显示的文档信息,比如GNU项目的文档。
Linux info命令适用的Linux版本
info命令是GNU项目的一部分,它在大多数Linux发行版中都是默认安装的,比如Ubuntu、Debian、Fedora、CentOS等。如果你的Linux系统中没有info命令,你可以使用以下命令来安装它:
- 对于基于Debian的系统,如Ubuntu,使用apt-get命令:
[linux@bashcommandnotfound.cn ~]$ sudo apt-get install texinfo
- 对于基于Red Hat的系统,如Fedora,使用dnf命令:
[linux@bashcommandnotfound.cn ~]$ sudo dnf install texinfo
- 对于基于Red Hat的系统,如CentOS 7,使用yum命令:
[linux@bashcommandnotfound.cn ~]$ sudo yum install texinfo
- 对于基于Red Hat的系统,如CentOS 8,使用dnf命令:
[linux@bashcommandnotfound.cn ~]$ sudo dnf install texinfo
Linux info命令的基本语法
info命令的基本语法格式如下:
info [options] [menu-item...]
其中,options是可选的参数,用来控制info命令的行为和输出;menu-item是可选的菜单项,用来指定要查看的文档信息的主题或节。如果不指定任何参数或菜单项,info命令会显示info目录,也就是所有可用的文档信息的列表。
Linux info命令的常用选项或参数说明
info命令有很多选项或参数,可以用来改变info命令的行为和输出。这里列举一些最常用的选项或参数,以及它们的作用:
| 选项或参数 | 作用 | 
|---|---|
| -a或--all | 显示所有匹配的文档信息,而不是只显示第一个匹配的文档信息 | 
| -d或--directory | 指定要搜索的文档信息的目录,可以有多个目录,用冒号分隔 | 
| -f或--file | 指定要查看的文档信息的文件名 | 
| -h或--help | 显示info命令的帮助信息,并退出 | 
| -n或--node | 指定要查看的文档信息的节点名 | 
| -o或--output | 将文档信息输出到指定的文件中,而不是显示在屏幕上 | 
| -v或--version | 显示info命令的版本信息,并退出 | 
Linux info命令的实例
info命令的实例有很多,可以根据不同的需求和场景来使用。这里列举一些最常用的实例,以及它们的效果:
实例1:查看info目录
如果不指定任何参数或菜单项,info命令会显示info目录,也就是所有可用的文档信息的列表。这是info命令的默认行为,可以用来浏览和选择想要查看的文档信息。命令如下:
[linux@bashcommandnotfound.cn ~]$ info
输出如下(部分省略):
File: dir,      Node: Top,      This is the top of the INFO tree.
  This (the Directory node) gives a menu of major topics.
  Typing "q" exits, "?" lists all Info commands, "d" returns here,
  "h" gives a primer for first-timers,
  "mEmacs<Return>" visits the Emacs manual, etc.
  In Emacs, you can click mouse button 2 on a menu item or cross reference
  to select it.
* Menu:
Documentation
* Info: (info).         How to use the documentation browsing system.
Emacs
* Emacs: (emacs).       The extensible self-documenting text editor.
* Emacs FAQ: (efaq).    Frequently Asked Questions about Emacs.
...
实例2:查看指定的命令信息
如果指定一个或多个菜单项,info命令会显示与之匹配的文档信息。菜单项可以是文档信息的主题或节,也可以是文档信息的节点名。如果有多个菜单项,info命令会依次显示它们,可以用n和p键来切换下一个或上一个文档信息。命令如下:
[linux@bashcommandnotfound.cn ~]$ info ls cp
输出如下(部分省略):
File: coreutils.info,  Node: ls invocation,  Next: dir invocation,  Up: Directory listing
10.1 'ls': List directory contents
==================================
...
实例3:查看指定的文档信息的节点
如果指定一个文档信息的节点名,info命令会显示与之匹配的文档信息的节点。节点是文档信息的最小单位,它包含了一些相关的信息和链接。节点名可以用-n或--node选项来指定,也可以直接写在文档信息的后面,用圆括号括起来。命令如下:
[linux@bashcommandnotfound.cn ~]$ info -n "General output formatting" ls
[linux@bashcommandnotfound.cn ~]$ info ls "(General output formatting)"
输出如下(部分省略):
File: coreutils.info,  Node: General output formatting,  Next: What information is listed,  Prev: ls invocation,  Up: ls invocation
10.1.1 General output formatting
--------------------------------
...
实例4:显示所有匹配的文档信息
如果指定一个或多个菜单项,info命令默认只显示第一个匹配的文档信息。如果想要显示所有匹配的文档信息,可以使用-a或--all选项。这样,info命令会显示所有与菜单项相关的文档信息,可以用n和p键来切换下一个或上一个文档信息。命令如下:
[linux@bashcommandnotfound.cn ~]$ info -a ls
输出如下(部分省略):
File: coreutils.info,  Node: ls invocation,  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.
   For non-option command-line arguments that are directories, by
default 'ls' lists the contents of directories, not recursively, and
omitting files with names beginning with '.'.  For other non-option
arguments, by default 'ls' lists just the file name.  If no non-option
argument is specified, 'ls' operates on the current directory, acting
as if it had been invoked with a single argument of '.'.
...
实例5:搜索关键词
使用-k选项,您可以搜索包含特定关键词的命令。
[linux@bashcommandnotfound.cn ~]$ info -k print
Linux Info命令的注意事项
如果在试图使用info时遇到“info: command not found”的错误,说明您的系统中没有安装info。您可以按照前文中的部分解决该问题。
 
       
       
      
评论区