在linux系统上怎么获取命令的帮助信息及man文档划分

如何在linux系统上获取命令的帮助信息及man文档的章节划分

1、命令 -- help

2、man 命令

后者更加详细

首先帮助中尖括号<>和方括号[]以及省略号...的含义,

在方括号内的表达式(“[” 和 “]”之间的字符)是可选的(写命令时要去掉括号)。
在尖括号内的表达式(“[” 和 “]”之间的字符)是必须替换的表达式(而且要去掉括号)。

省略号表示该选项可以单个或多个

以7z的参数为例:

7z [...] <archive_name> [<file_names>...] [<@listfiles...>]

7z <命令行> [[选项]...] <档案名称(压缩包名称)> [<被压缩的文件名>...] [<@文件列表(如txt文件中的文件列表)...>]

实例分析:

7z a -tzip -p111 archive.zip txt.txt txt.txt文件压缩为archive.zip,压缩方式为zip 密码为111
7z x -tzip -p111 archive.zip 解压 密码为111
a为命令,命令至少要有一个

-t /-p为选项(switch),可选0个或多个,zip和111分别为-t和-p的参数,中间不需要空格 选项(如-r)放前放后都行

7z的命令不区分大小写,有些命令如cp要区分。。。注意了

命令要点参考

a: Add files to archive 添加文件到压缩包中
b: Benchmark
d: Delete files from archive 从压缩包中删除文件
e: Extract files from archive (without using directory names) 从压缩档案中释放文件到当前目录中。或者到指定的输出文件夹。输出文件夹设置可以通过 -o (设置输出文件夹) 选项来更改。
l: List contents of archive 查看压缩包中文件列表
t: Test integrity of archive
u: Update files to archive
x: eXtract files with full paths 在当前目录中,使用完整路径从压缩档案中释放文件.或者到指定的输出文件夹。更多详细内容请参阅 e (释放) 命令。
示例
7z x archive.zip
从压缩档案 archive.zip 中释放所有文件到当前文件夹。
7z x archive.zip -oc:soft *.cpp
从压缩档案 archive.zip 中释放 *.cpp 文件到 c:soft 文件夹。

-ai[r[-|0]]{@listfile|!wildcard}: Include archives -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives -bd: Disable percentage indicator -i[r[-|0]]{@listfile|!wildcard}: Include filenames -m{Parameters}: set compression Method -o{Directory}: set Output directory 目标文件目录 -p{Password}: set Password {}大括号中为改选项多参数,有些有参数,有些没有 -r[-|0]: Recurse subdirectories -scs{UTF-8 | WIN | DOS}: set charset for list files -sfx[{name}]: Create SFX archive -si[{name}]: read data from stdin -slt: show technical information for l (List) command -so: write data to stdout -ssc[-]: set sensitive case mode -t{Type}: Set type of archive -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options -v{Size}[b|k|m|g]: Create volumes -w[{path}]: assign Work directory. Empty path means a temporary directory -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames -y: assume Yes on all queries

选项要点参考
选项 说明
-- 阻止选项解析
-ai 附件档案文件名
-an 不解析档案名称
-ao 覆盖模式
-ax 排除档案文件名
-i 包括文件名
-m 设置压缩算法
-o 设置输出目录 常用
-p 设置密码
-r 递归子目录 常用
-sfx 创建自释放档案
-si 从StdIn 读取数据
-so 从StdOut 写入数据
-t 设置档案类型
-u 更新选项
-v 创建分卷
-w 设置工作目录
-x 文件名排除
-y 全是
-- (阻止选项解析) 选项
在命令行中使“--”后的选项开关“-”都失效。这样就允许在命令行中使用文件名以“-”开头的文件。

man文档的章节划分

Linux提供了丰富的帮助手册,当你需要查看某个命令的参数时不必到处上网查找,只要man一下即可。

Linux的man手册共有以下几个章节:

代號 代表內容
1 使用者在shell中可以操作的指令或可执行档
2 系統核心可呼叫的函数与工具等
3 一些常用的函数(function)与函数库(library),大部分是C的函数库(libc)
4 装置档案的说明,通常在/dev下的档案
5 设定档或者是某些档案的格式
6 游戏(games)
7 惯例与协定等,例如Linux档案系统、网络协定、ASCII code等等的說明
8 系統管理員可用的管理指令
9 跟kernel有关的文件

如:man 5 data

1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]

1、Standard commands (标准命令)
2、System calls (系统调用)
3、Library functions (库函数)
4、Special devices (设备说明)
5、File formats (文件格式)
6、Games and toys (游戏和娱乐)
7、Miscellaneous (杂项)
8、Administrative Commands (管理员命令)
9 其他(Linux特定的), 用来存放内核例行程序的文档。

n 新文档, 可能要移到更适合的领域。
o 老文档, 可能会在一段期限内保留。
l 本地文档, 与本特定系统有关的。

例如:我们输入 man ls,它会在最左上角显示“LS(1)”,在这里,“LS”表示手册名称,而“(1)”表示该手册位于第一节章,同样,我们输入“man ifconfig”它会在最左上角显示“IFCONFIG(8)”。也可以这样输入命令:“man [章节号] 手册名称”。

man是按照手册的章节号的顺序进行搜索的,比如:
man sleep
只会显示sleep命令的手册,如果想查看库函数sleep,就要输入:
man 3 sleep

ubuntu默认是没有安装c语言的库函数man手册的

1.添加库函数手册
ubuntu默认是没有安装c语言的库函数man手册的,所以你在man perror 和sendto之类的函数时会显示没有相关文档的问题,这个问题让我郁闷了我好久。解决方法:
sudo apt-get install manpages-dev
2.让man显示中文
ubuntu源里面已经包含了中文的man包,所以不用从其他地方down了,直接
sudo apt-get install manpages-zh
但是这样man默认显示的还不是中文,还需要以下两步
a.把中文man包转换成utf8格式的
新建一个脚本文件
gedit t.sh
把下面内容添加进去
#!/bin/bashcd /usr/share/man/zh_CN/for k in *docd $kfor i in *.gzdo j=echo ${i%.gz} gunzip $i iconv -f gb18030 -t utf8 $j >tmp mv tmp $j gzip $jdonecd ..done
然后
sudo ./t
b.修改man默认的语言
sudo gedit /etc/manpath.config 把里面的所有的 /usr/share/man 改成 /usr/share/man/zh_CN
保存后退出,然后你再试一下man ls
3.让没有中文帮助的显示英文
做完上面第二部还不够,这时你再man 一下一些c语言函数(不要用printf,socket之类比较有名的函数,这些已经有中文帮助了)的时候就会发现竟然没有帮助,而刚才明明在第一步已经安装了啊。这是因为你上面 把/usr/share/man 改成 /usr/share/man/zh_CN的操作使man只在中文帮助中搜索,如果没有就直接放弃,因此还需要以下操作,才能让man在没有中文帮助的时候自动显示英文的帮助,如果英文的也没有,哪就真的没有了。
sudo gedit /etc/manpath.config
然后搜索你刚才改过的地方,然后在其后面添加同样的一行,只是后面的目录还用原来的/usr/share/man,比如在修改后的
MANPATH_MAP /bin /usr/share/man/zh_CN
再添加一行
MANPATH_MAP /bin /usr/share/man

原文地址:https://www.cnblogs.com/ZhengLiming/p/5875074.html