4.Linux 中获取帮助(从零开始学)
1.Man 手册
1.1 man 简介
man,manual 简称。man使用不同 section 区分手册类别。
| SECTION | 内容类型 |
|---|---|
| 1 | 用户命令(可执行命令和shell程序) |
| 2 | 系统调用(从用户空间调用的内核例程) |
| 3 | 库函数(由程序库提供) |
| 4 | 特殊文件(如设备文件) |
| 5 | 文件格式(用于许多配置文件和结构) |
| 6 | 游戏(过去的有趣程序章节) |
| 7 | 惯例、标准和其他(协议、文件系统) |
| 8 | 系统管理和特权命令(维护任务) |
| 9 | Linux内核API(内核调用) |
1.2 man 命令
[fengkai@centos7 ~ 19:02:45]$ man --help Usage: man [OPTION...] [章节] 手册页... # man命令将会调用less打开/usr/share/man/相关文件 # passwd(1)描述passwd命令更改密码 [laoma@CentOS7 ~]$ man 1 passwd # passwd(5)解释/etc/passwd文件格式 [laoma@CentOS7 ~]$ man 5 passwd # 查看英文的帮助手册,指定LANG变量 [laoma@centos7 ~]$ LANG=en_US.utf8 man gedit # 或者 [laoma@centos7 ~]$ LANG=en_US.utf8 [laoma@centos7 ~]$ man geditman手册页面交互操作指令(less程序)
| 命令 | 结果 |
|---|---|
| PageDown或者空格键 | 向前(向下)滚动一个屏幕 |
| PageUp | 向后(向上)滚动一个屏幕 |
| 向下箭头 | 向前(向下)滚动一行 |
| 向上箭头 | 向后(向上)滚动一行 |
| d | 向前(向下)滚动半个屏幕 |
| u | 向后(向上)滚动半个屏幕 |
| /string | 在man page中向前(向下)搜索string |
| n | 在man page中重复之前的向前(向下)搜索 |
| N | 在man page中重复之前的向后(向上)搜索 |
| g | 转到man page的第一行。 |
| G | 转到man page的最后一行。 |
| q | 退出man ,并返回到shell命令提示符 |
# 使用root用户更新man page库 [root@centos7 ~]# mandb 正在删除 /usr/share/man 里的旧数据库条目... mandb: 警告:/usr/share/man/man8/fsck.fat.8.manpage-fix.gz:忽略错误的文件名 ... ... 正在处理 /usr/share/man/en 下的手册页... 正在删除 /usr/local/share/man 里的旧数据库条目... 正在处理 /usr/local/share/man 下的手册页... 0 man subdirectories contained newer manual pages. 0 manual pages were added. 0 stray cats were added. 17 old database entries were purged. # 使用 -k 选线搜索关键字 [laoma@centos7 ~]$ man -k passwd chgpasswd (8) - 批量更新组密码 chpasswd (8) - 批量更新密码 gpasswd (1) - administer /etc/group and /etc/gshadow mkpasswd (1) - 为用户产生新口令 passwd (5) - (未知的主题) ... ... [laoma@centos7 ~]$ man -k ext4 ..... resize2fs (8) - ext2/ext3/ext4 file system resizer ...... [laoma@centos7 ~]$ man resize2fs补充:命令的来源
- 安装软件包之后获得
- shell 自带的工具
1.3 查看 shell 自带命令
# 不建议使用man查询 [laoma@centos7 ~]$ man history # 使用 help command [laoma@centos7 ~]$ help history history: history [-c] [-d 偏移量] [n] 或 history -anrw [文件名] 或 history -ps 参数 [参数...] 显示或操纵历史列表。 带行号显示历史列表,将每个被修改的条目加上前缀 `*'。 参数 N 会仅列出最后的 N 个条目。 ......==重要:==通用选项--help,也用于查看命令帮助。
1.4 /usr/share/doc
可以通过file:///usr/share/doc浏览。一些包还含拓展示例,配置文件模板,脚本,使用说明或用户指导手册。例如:/usr/share/doc/dhclient-*。
[laoma@centos7 ~]$ cat /usr/share/doc/dhclient-4.2.5/dhclient.conf.example1.5 which 和 whereis 命令
# 查看vi命令代表什么 [laoma@centos7 ~]$ which vi alias vi='vim' /usr/bin/vim # whereis 查看关键字对应的程序位置,帮助文档,源码 [laoma@centos7 ~]$ whereis man man: /usr/bin/man /usr/share/man /usr/share/man/man1/man.1.gz /usr/share/man/man1p/man.1p.gz /usr/share/man/man7/man.7.gz [laoma@centos7 ~]$ whereis passwd passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz1.6 综合测试
查找并查看以下 man 手册,并举例验证。
1.查看 man 命令使用方法。
#man直接查询 [fengkai@centos7 ~ 09:33:17]$ man su #man直接查询不到的用-k查询 [fengkai@centos7 ~ 13:28:59]$ man -K kernel #man用-k查询太多,使用|符号进行匹配 [fengkai@centos7 ~ 11:16:11]$ man -k kernel | grep boot2.查看 gedit 命令使用方法:如何使用gedit打开文件、打开文件的时候如何定位到特定行和列。
在虚拟机界面使用终端打开/etc/hosts文件,打开之后当前终端会卡住
需要在新终端中打开/etc/hosts文件的第一行第五列
3.查看 su 命令使用方法:不带参数作用和带-作用。
[fengkai@centos7 ~ 11:10:41]$ man su SU(1) User Commands SU(1) NAME su - run a command with substitute user and group ID SYNOPSIS su [options...] [-] [user [args...]] DESCRIPTION su allows to run commands with substitute user and group ID. When called without arguments su defaults to running an interactive shell as root. For backward compatibility su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOGNAME if the target user is not root). It is recommended to always use the --login option (instead it's shortcut -) to avoid side effects caused by mixing environments. This version of su uses PAM for authentication, account and session management. Some configuration options found in other su implementations such as e.g. support of a wheel group have to be configured via PAM. ······· -, -l, --login Starts the shell as login shell with an environment similar to a real login: o clears all environment variables except for TERM o initializes the environment variables HOME, SHELL, USER, LOG- NAME, PATH o changes to the target user's home directory o sets argv[0] of the shell to '-' in order to make the shell a login shell ···········4.查找 调整内核(kernel)启动(boot)参数 手册。
#用man -k查找kernel,通过 | 匹配boot。其中bootparam应该是说明启动参数的 [fengkai@centos7 ~ 10:47:23]$ man -k kernel | grep boot bootparam (7) - introduction to boot time parameters of the Linux kernel kernel-install (8) - Add and remove kernel and initramfs images to and from /boot kexec (8) - directly boot into a new kernel modules-load.d (5) - Configure kernel modules to load at boot sysctl.d (5) - Configure kernel parameters at boot systemd-modules-load (8) - Load kernel modules at boot systemd-modules-load.service (8) - Load kernel modules at boot systemd-sysctl (8) - Configure kernel parameters at boot systemd-sysctl.service (8) - Configure kernel parameters at boot #打开bootparam,查看里面的相关参数,达到要求 [fengkai@centos7 ~ 10:48:09]$ man bootparam BOOTPARAM(7) Linux Programmer's Manual BOOTPARAM(7) NAME bootparam - introduction to boot time parameters of the Linux kernel DESCRIPTION The Linux kernel accepts certain 'command-line options' or 'boot time parameters' at the moment it is started. In general this is used to supply the kernel with information about hardware parameters that the kernel would not be able to deter- mine on its own, or to avoid/override the values that the kernel would otherwise detect. When the kernel is booted directly by the BIOS (say from a floppy to which you copied a kernel using 'cp zImage /dev/fd0'), you have no opportunity to specify any parameters. So, in order to take advantage of this possibility you have to use a boot loader that is able to pass parameters, such as GRUB. ·············5.查找 创建 archive 工具 手册,并使用对应工具创建archive文件和提取archive文件。(不允许使用 zip和unzip)。
[fengkai@centos7 ~ 11:09:27]$ man -k archive ar (1) - create, modify, and extract from archives ar (1p) - create and maintain library archives cpio (1) - copy files to and from archives cpio (5) - format of cpio archive files cpio.h (0p) - cpio archive values db_archive (1) - Find unused log files for archival funzip (1) - filter for extracting from a ZIP archive in a pipe gpg-zip (1) - Encrypt or sign files into an archive osinfo-db-export (1) - Export to a osinfo database archive osinfo-db-import (1) - Import an osinfo database archive pax (1p) - portable archive interchange ranlib (1) - generate index to archive. rpm2cpio (8) - Extract cpio archive from RPM Package Manager (RPM) package. tar (5) - format of tape archive files unzip (1) - list, test and extract compressed files in a ZIP archive unzipsfx (1) - self-extracting stub for prepending to ZIP archives zip (1) - package and compress (archive) files zipgrep (1) - search files in a ZIP archive for lines matching a pattern zipinfo (1) - list detailed information about a ZIP archive [fengkai@centos7 ~ 17:31:10]$ man tar TAR(1) User Commands TAR(1) NAME tar - manual page for tar 1.26 SYNOPSIS tar [OPTION...] [FILE]... DESCRIPTION GNU `tar' saves many files together into a single tape or disk ar- chive, and can restore individual files from the archive. Note that this manual page contains just very brief description (or more like a list of possible functionality) originally generated by the help2man utility. The full documentation for tar is maintained as a Texinfo manual. If the info and tar programs are properly installed at your site, the command `info tar' should give you access to the complete manual. EXAMPLES tar -cf archive.tar foo bar # Create archive.tar from files foo and bar. tar -tvf archive.tar # List all files in archive.tar verbosely. tar -xf archive.tar # Extract all files from archive.tar. ····· #根据说明用tar -cf将file-1 file-2 file-3打包为file.tar [fengkai@centos7 ~ 17:34:03]$ tar cf file.tar file-1 file-2 file-3 [fengkai@centos7 ~ 17:35:06]$ ls allinone file-1 file.tar passwd.list profile 公共 图片 音乐 dhcpd.conf file-2 passwd2.list passwd.man profile.sh 模板 文档 桌面 ext4.man file-3 passwd.all passwd.stdout testfile 视频 下载 #删除file-1 file-2 file-3后,根据说明用tar -xf将file.tar解压出来 [fengkai@centos7 ~ 17:37:09]$ rm file-[1-3] [fengkai@centos7 ~ 17:55:59]$ ls allinone file.tar passwd.list profile 公共 图片 音乐 dhcpd.conf passwd2.list passwd.man profile.sh 模板 文档 桌面 ext4.man passwd.all passwd.stdout testfile 视频 下载 [fengkai@centos7 ~ 17:56:00]$ tar -xf file.tar [fengkai@centos7 ~ 17:56:15]$ ls allinone file-1 file.tar passwd.list profile 公共 图片 音乐 dhcpd.conf file-2 passwd2.list passwd.man profile.sh 模板 文档 桌面 ext4.man file-3 passwd.all passwd.stdout testfile 视频 下载 [fengkai@centos7 ~ 17:56:16]$