公司动态

4.Linux 中获取帮助(从零开始学)

📅 2026/7/17 21:34:15
4.Linux 中获取帮助(从零开始学)
1.Man 手册1.1 man 简介manmanual 简称。man使用不同 section 区分手册类别。SECTION内容类型1用户命令可执行命令和shell程序2系统调用从用户空间调用的内核例程3库函数由程序库提供4特殊文件如设备文件5文件格式用于许多配置文件和结构6游戏过去的有趣程序章节7惯例、标准和其他协议、文件系统8系统管理和特权命令维护任务9Linux内核API(内核调用)1.2 man 命令[fengkaicentos7 ~ 19:02:45]$ man --help Usage: man [OPTION...] [章节] 手册页... # man命令将会调用less打开/usr/share/man/相关文件 # passwd(1)描述passwd命令更改密码 [laomaCentOS7 ~]$ man 1 passwd # passwd(5)解释/etc/passwd文件格式 [laomaCentOS7 ~]$ man 5 passwd # 查看英文的帮助手册指定LANG变量 [laomacentos7 ~]$ LANGen_US.utf8 man gedit # 或者 [laomacentos7 ~]$ LANGen_US.utf8 [laomacentos7 ~]$ man geditman手册页面交互操作指令less程序命令结果PageDown或者空格键向前向下滚动一个屏幕PageUp向后向上滚动一个屏幕向下箭头向前向下滚动一行向上箭头向后向上滚动一行d向前向下滚动半个屏幕u向后向上滚动半个屏幕/string在man page中向前向下搜索stringn在man page中重复之前的向前向下搜索N在man page中重复之前的向后向上搜索g转到man page的第一行。G转到man page的最后一行。q退出man 并返回到shell命令提示符# 使用root用户更新man page库 [rootcentos7 ~]# 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 选线搜索关键字 [laomacentos7 ~]$ man -k passwd chgpasswd (8) - 批量更新组密码 chpasswd (8) - 批量更新密码 gpasswd (1) - administer /etc/group and /etc/gshadow mkpasswd (1) - 为用户产生新口令 passwd (5) - (未知的主题) ... ... [laomacentos7 ~]$ man -k ext4 ..... resize2fs (8) - ext2/ext3/ext4 file system resizer ...... [laomacentos7 ~]$ man resize2fs补充命令的来源安装软件包之后获得shell 自带的工具1.3 查看 shell 自带命令# 不建议使用man查询 [laomacentos7 ~]$ man history # 使用 help command [laomacentos7 ~]$ 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-*。[laomacentos7 ~]$ cat /usr/share/doc/dhclient-4.2.5/dhclient.conf.example1.5 which 和 whereis 命令# 查看vi命令代表什么 [laomacentos7 ~]$ which vi alias vivim /usr/bin/vim # whereis 查看关键字对应的程序位置帮助文档源码 [laomacentos7 ~]$ 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 [laomacentos7 ~]$ 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直接查询 [fengkaicentos7 ~ 09:33:17]$ man su #man直接查询不到的用-k查询 [fengkaicentos7 ~ 13:28:59]$ man -K kernel #man用-k查询太多使用|符号进行匹配 [fengkaicentos7 ~ 11:16:11]$ man -k kernel | grep boot2.查看 gedit 命令使用方法如何使用gedit打开文件、打开文件的时候如何定位到特定行和列。在虚拟机界面使用终端打开/etc/hosts文件打开之后当前终端会卡住需要在新终端中打开/etc/hosts文件的第一行第五列3.查看 su 命令使用方法不带参数作用和带-作用。[fengkaicentos7 ~ 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 its 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 users 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应该是说明启动参数的 [fengkaicentos7 ~ 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查看里面的相关参数达到要求 [fengkaicentos7 ~ 10:48:09]$ man bootparam BOOTPARAM(7) Linux Programmers 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。[fengkaicentos7 ~ 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 [fengkaicentos7 ~ 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 [fengkaicentos7 ~ 17:34:03]$ tar cf file.tar file-1 file-2 file-3 [fengkaicentos7 ~ 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解压出来 [fengkaicentos7 ~ 17:37:09]$ rm file-[1-3] [fengkaicentos7 ~ 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 视频 下载 [fengkaicentos7 ~ 17:56:00]$ tar -xf file.tar [fengkaicentos7 ~ 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 视频 下载 [fengkaicentos7 ~ 17:56:16]$