31人参与 • 2025-08-06 • Linux
info
是 linux 系统中用于查看 gnu 软件文档的命令行工具,提供交互式、结构化的方式访问详细帮助信息。与 man
命令相比,info
文档更全面,组织更模块化,支持超链接导航,适合深入学习 gnu 工具和库的用法。作为 gnu 项目的一部分,info
广泛应用于 linux 发行版(如 ubuntu、centos、arch linux),为开发者、系统管理员和用户提供强大的技术参考。
info
是 linux 命令行工具,用于浏览以 info 格式编写的 gnu 软件文档。
info 文档是 gnu 项目开发的超文本文档系统,基于 texinfo 格式,涵盖 gnu 工具(如 gcc
、bash
)、库(如 libc
)及系统的详细说明。相比 man
页面注重简洁参考,info
文档更像结构化的电子书,包含章节、子章节、索引和交叉引用,适合系统性学习。
info
通过交互式界面或直接查询访问文档,支持导航、搜索和定制化输出,是 linux 用户获取技术信息的重要工具。
/usr/share/info
。退出状态:
info [选项] [主题] [节点]
参数说明
bash
、gcc
)。commands
),可选。选项:
-f, --file=file
:指定 info 文件路径。-n, --node=node
:直接打开指定节点。-o, --output=file
:输出到文件。-w, --where
:显示文档路径。--apropos=string
:搜索相关文档。--index-search=string
:搜索索引。-h, --help
:显示帮助。--version
:显示版本。输出行为
依赖 texinfo:
确保安装 texinfo
包:
sudo apt install texinfo # ubuntu sudo dnf install texinfo # centos
文档位置:
/usr/share/info
,可通过 infopath
扩展。键盘导航:
n
、p
、q
)。与 man 区别:
info
更详细,适合学习;man
更简洁,适合快速参考。网络限制:
安全性:
bash
、gcc
等工具用法。libc
或 make
的详细文档。coreutils
)配置说明。以下示例假设运行在 bash shell(如 ubuntu 24.04,当前时间为 2025年6月12日周四下午3:27 cst)。测试环境为标准 linux 系统(如 ubuntu、centos),确保 info
和 texinfo
已安装(info --version
)。示例涉及常见 gnu 工具(如 bash
、coreutils
)的文档查询,使用交互和非交互模式。命令在终端运行,假设 /usr/share/info
包含必要文档。
检查 info
info --version
输出:
info (gnu texinfo) 7.1
检查 texinfo
dpkg -l | grep texinfo # ubuntu rpm -q texinfo # centos
验证文档
ls /usr/share/info | head -n 5
输出:
bash.info.gz coreutils.info.gz gcc.info.gz glibc.info.gz make.info.gz
命令
info bash
说明
bash
info 文档。输出(交互模式)
file: bash.info, node: top, next: introduction, up: (dir) bash reference manual ******************** this manual is the reference for bash, the gnu bourne-again shell... * menu: * introduction:: an introduction to the shell. * definitions:: some definitions used in the rest of this manual. * basic shell features:: the basic features of the shell. ... --:-- (bash)top
导航
n
:下一节点。p
:上一节点。u
:返回父节点。q
:退出。命令
info bash 'shell variables'
说明
bash
文档中的“shell variables”节点。输出(交互模式)
file: bash.info, node: shell variables, next: bash variables, up: variables 5.2 shell variables ================== variables are used to store data in the shell... * menu: * bourne shell variables:: variables recognized by bourne shells. * special parameters:: parameters with special meaning. ...
命令
info bash 'shell variables' -o /tmp/variables.txt cat /tmp/variables.txt | head -n 10
说明
/tmp/variables.txt
。输出
shell variables *************** variables are used to store data in the shell... * bourne shell variables: variables recognized by bourne shells. * special parameters: parameters with special meaning. ...
命令
info --apropos grep
说明
grep
相关的文档。输出
"(coreutils)grep invocation" -- grep "(grep)top" -- grep "(regex)top" -- regular expressions ...
命令
info bash --index-search path
说明
bash
文档索引中搜索“path”。输出(交互模式)
file: bash.info, node: bourne shell variables, up: shell variables 5.2.1 bourne shell variables ---------------------------- `path` the search path for commands...
命令
info --where bash
说明
bash
info 文件路径。输出
/usr/share/info/bash.info.gz
选项 | 描述 |
---|---|
-f file | 指定 info 文件 |
-n node | 打开特定节点 |
--apropos=string | 搜索相关主题 |
--index-search=string | 搜索索引 |
示例
info -f /usr/share/info/gcc.info.gz
选项 | 描述 |
---|---|
-o file | 输出到文件 |
--subnodes | 包含子节点 |
--output=- | 输出到 stdout |
示例
info bash --subnodes -o /tmp/bash_full.txt
变量 | 描述 |
---|---|
infopath | info 文件搜索路径 |
pager | 输出分页器(如 less ) |
示例
export infopath=/custom/info:$infopath info mydoc
info
的高级用法涉及脚本化、自定义 info 文件、与其他工具结合以及自动化文档任务,适合开发者和管理员。
脚本
#!/bin/bash topics=("bash" "gcc" "make") for topic in "${topics[@]}"; do info "$topic" --subnodes -o "/tmp/${topic}_doc.txt" echo "已提取 $topic 文档" done
说明
输出
已提取 bash 文档 已提取 gcc 文档 已提取 make 文档
texinfo 源文件 (/tmp/example.texi)
\input texinfo @setfilename example.info @settitle 示例手册 @node top @top 示例手册 这是一个示例 info 文档。 @menu * 第一章:: 第一章内容。 @end menu @node 第一章 @chapter 第一章 第一章的内容。 @end texinfo
命令
makeinfo --info /tmp/example.texi -o /tmp/example.info info -f /tmp/example.info
说明
输出(交互模式)
file: example.info, node: top, next: 第一章, up: (dir) 示例手册 ******** 这是一个示例 info 文档。 * menu: * 第一章:: 第一章内容。
命令
info bash --subnodes | grep -i "environment variable"
说明
bash
文档中搜索“environment variable”。输出
5.2 shell variables environment variables are used to... * path: the search path for commands. ...
脚本
#!/bin/bash topic=$1 keyword=$2 info "$topic" --index-search="$keyword" -o /tmp/result.txt if [ $? -eq 0 ]; then cat /tmp/result.txt | head -n 10 else echo "在 $topic 中未找到 $keyword" fi
示例
./script.sh bash path
说明
输出
`path` the search path for commands...
命令
mkdir /tmp/custom_info cp /tmp/example.info /tmp/custom_info/ export infopath=/tmp/custom_info:$infopath info example
说明
输出(交互模式)
file: example.info, node: top, next: 第一章, up: (dir) ...
文档可用性:
确保安装 info 文件:
sudo apt install bash-doc # ubuntu
导航学习曲线:
n
、p
、m
、q
)。文件压缩:
.gz
格式,自动处理。man 作为备选:
无 info 文档时尝试 man
:
man bash
环境变量:
检查 infopath
:
echo $infopath
以下是高级技巧和实战案例,展示 info
在复杂场景中的应用。
脚本
#!/bin/bash echo "输入主题(如 bash、gcc):" read topic info "$topic" --subnodes -o "/tmp/${topic}_ref.txt" gzip "/tmp/${topic}_ref.txt" echo "文档已保存为 /tmp/${topic}_ref.txt.gz"
说明
输出
输入主题(如 bash、gcc): bash 文档已保存为 /tmp/bash_ref.txt.gz
脚本
#!/bin/bash topic="coreutils" keywords=("ls" "cp" "mv") for keyword in "${keywords[@]}"; do echo "在 $topic 中搜索 $keyword:" info "$topic" --index-search="$keyword" -o "/tmp/${keyword}.txt" cat "/tmp/${keyword}.txt" | head -n 5 done
说明
输出
在 coreutils 中搜索 ls: `ls` list directory contents... 在 coreutils 中搜索 cp: `cp` copy files and directories...
脚本
#!/bin/bash info_file=/tmp/example.info if [ -o "$info_file" ]; then info -f "$info_file" else echo "不可信的 info 文件" exit 1 fi
说明
输出
不可信的 info 文件
脚本
#!/bin/bash dest=/tmp/info_backup mkdir -p "$dest" cp /usr/share/info/*.info.gz "$dest" for file in "$dest"/*.info.gz; do info -f "$file" --subnodes -o "${file%.gz}.txt" done echo "备份完成,位于 $dest"
说明
输出
备份完成,位于 /tmp/info_backup
脚本
#!/bin/bash echo "输入主题和关键词(如 bash path):" read topic keyword info "$topic" --index-search="$keyword" --output=- | less
说明
输出
`path` the search path for commands... (按 q 退出)
info
是 linux 系统中访问 gnu 结构化文档的强大工具,适合学习和参考。本文从基础到高级,结合详细示例和注意事项,全面介绍了 info
的功能。无论是探索 bash
特性、创建自定义 info 文件还是自动化文档任务,info
都能提供可靠支持。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论