如何查看Linux帮助
Linux涉及的命令非常多,每条命令涉及的参数也很多,人生亦有涯而知也无涯,有限的生命很难去记住这么多的命令,而且后续还在不停地更新。此时如果有个小助手就好了,可能你习惯用google、百度来找帮助,其实Linux提供了强大的帮助功能,熟练使用Linux自带的帮助功能,获取信息更快,学习起来也更系统。Bingo!让我们来一起学习如何查看Linux帮助吧。
常用Linux帮助有:
1、 Tab:补全命令
2、 whatis:显示简短功能描述,只告诉命令的作用,如“whatis ls”则会告诉你ls是什么以及作用,不会包含语法
3、 help:显示使用摘要和参数列表(可以查看大多数命令的用法)
4、 man:查看命令描述或手册页(Manual)
5、 info:查看命令详细的说明文件
(注:info查看的是比man更详细的说明,也就是把man的页再划分为更小的章节)
以下对tab补全、help和man做进一步详细介绍。
Tab补全允许用户在提示符下键入足够的内容以使其为以后快速补全命令或文件名。如果键入的字符不唯一,则按Tab键两次可显示以键入的字符为开头的所有命令。
root@Node01:~# pas
passwd paste paster paster2.7
root@Node01:~# pass
root@Node01:~# passwd
Enter new UNIX password:
Tab补全可以用于键入文件名作为命令的参数时将它们补全。按Tab键时,它将尽可能将文件名补充完整。再按一次Tab时,shell将列出与当前模式匹配的所有文件。键入额外字符直到名称唯一为止,然后使用Tab补全结束该命令行。
root@Node01:~# ls /etc/pas
root@HZ-CAS01-CVK01:~# ls /etc/passwd
passwd passwd-
许多命令可以通过Tab补全匹配参数和选项。Useradd命令供超级用户root在系统上创建其他用户。它有许多选项,可用于控制该命令的行为。键入选项部分内容后使用Tab补全可以将选项补充完整,而无需大量的键入操作。
root@Node01:~# useradd --
--base-dir --defaults --groups --inactive --no-log-init --password --skel --user-group
--comment --expiredate --help --key --non-unique --selinux-user --system
--create-home --gid --home-dir --no-create-home --no-user-group --shell --uid
root@HZ-CAS01-CVK01:~# useradd --
在bash shell中,Linux的命令分为两种:一种是系统shell自带的命令(builtin),这些我们叫作内部命令;二是外部命令,即在文件系统上的某位置有一个与命令名称对应的可执行文件。
判断一个命令是内部命令还是外部命令,可以用type命令。如下,cd命令为内部命令,mv和cp查看类型输出的是对应的可执行文件即为外部命令。
root@Node01:~# type cd
cd is a shell builtin
root@Node01:~# type mv
mv is /bin/mv
root@Node01:~# type cp
cp is hashed (/bin/cp)
1、内部命令获取帮助
命令格式:# help 命令名
2、外部命令获取帮助
命令格式:# 命令名 --help
如下,通过help来查看关于df命令的帮助,可以查看到df命令后面可以设置的选项,这些参数是无法通过Tab进行补全的。同时还可以查看到每个参数对应的含义。如常用的df –Th输出的结果就是“-T”参数指定的磁盘分区类型和“-h”参数指定的文件容量输出格式。
root@Node01:/# df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all include dummy file systems
-B, --block-size=SIZE scale sizes by SIZE before printing them. E.g.,
`-BM' prints sizes in units of 1,048,576 bytes.
See SIZE format below.
--total produce a grand total
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local file systems
--no-sync do not invoke sync before getting usage info (default)
-P, --portability use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE limit listing to file systems of type TYPE
-T, --print-type print file system type
-x, --exclude-type=TYPE limit listing to file systems not of type TYPE
-v (ignored)
--help display this help and exit
--version output version information and exit
root@Node01:/# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 28G 2.8G 24G 11% /
udev devtmpfs 7.7G 12K 7.7G 1% /dev
tmpfs tmpfs 3.1G 368K 3.1G 1% /run
none tmpfs 5.0M 0 5.0M 0% /run/lock
none tmpfs 7.7G 64K 7.7G 1% /run/shm
cgroup tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/sda5 ext4 19G 132M 18G 1% /var/log
/dev/sda7 ext4 398G 112M 378G 1% /vms
/dev/sdb ext4 826G 95G 689G 13% /opt/mds/disk/0
/dev/sde ocfs2 94G 4.7G 89G 5% /vms/sharefile01
1、 man命令简介
man page源自过去的Linux程序员手册,该手册篇幅很长,足以打印成多本书册。它们分别包含具体文件类型的消息,现已成为如下章节。文章被指代为主题,因为页面已不再使用。
Linux手册章节如下:
按键 |
执行结果 |
1 |
用户命令(可执行命令和shell程序) |
2 |
系统调用(从用户空间调用的内核例程) |
3 |
库函数(由程序 库提供) |
4 |
特殊文件(如设备文件) |
5 |
文件格式(用于许多配置文件和结构) |
6 |
游戏(过去的有趣程序章节) |
7 |
惯例、标准和其他(协议、文件系统) |
8 |
系统管理和特权命令(维护任务) |
9 |
Linux内核API(内核调用) |
说明:手册第9节最近添加到Linux中。并非所有man章节列表都会引用它。
为区分不同章节中相同的主题名称,man page参考中在主题后附加了章节编号(用括号括起)。例如,passwd(1)介绍用户命令即含有更改密码的命令,而passwd(5)说明文件格式即用于存储本地用户存储账户的/etc/passwd文件格式。
若要读取具体的man page,请使用man topic。主题内容一次显示一个屏幕。使用箭头键可单行滚动。或者使用空格键显示下一个屏幕。man命令以配置的顺序搜索手册章节,首先显示热门的章节。例如man passwd默认情况下显示passwd(1)。要显示具体章节的man page主题,请附上章节编号参数:man 5 passwd显示passwd(5)。
2、 根据关键字识别man page
能够高效搜索主题并在man手册中导航是一项重要的管理技能。下表列出了基本的man导航命令:
命令 |
执行结果 |
空格键 |
向下滚动一个屏幕 |
PageDown |
向下滚动一个屏幕 |
PageUp |
向上滚动一个屏幕 |
向下箭头键 |
向下滚动一行 |
向上箭头键 |
向下滚动一行 |
/string |
在man page中详细搜索string |
n |
在man page中重复之前的搜索项向下搜索 |
N |
在man page中重复之前的搜索项向上搜索 |
g |
转到man page的开头 |
g |
转到man page的末尾 |
q |
退出man,并返回shell提示符 |
重要:在执行搜索时,string允许使用正则表达式语法。简单的文本(如passwd)按照预期工作,正则表达式则适用于字符(如$、*、.和^)进行更复杂的模式匹配。因此,搜索包含程序表达式元字符的字符串(如make $$$)可能会产生意外的结果。
3、 根据关键字搜索man page
使用man –k keyword对man page执行关键字搜索,这会显示与关键字匹配的man page主题和章节编号的列表。
root@Node01:/# man -k passwd
chgpasswd (8) - update group passwords in batch mode
chpasswd (8) - update passwords in batch mode
Crypt::PasswdMD5 (3pm) - Provides interoperable MD5-based crypt() functions
gpasswd (1) - administer /etc/group and /etc/gshadow
grub-mkpasswd-pbkdf2 (1) - generate hashed password for GRUB
pam_localuser (8) - require users to be listed in /etc/passwd
passwd (1) - change user password
passwd (1ssl) - compute password hashes
passwd (5) - the password file
smbpasswd (5) - The Samba encrypted password file
smbpasswd (8) - change a user's SMB password
update-passwd (8) - safely update /etc/passwd, /etc/shadow and /etc/group
常见的系统管理主题在第1节(用户命令)、第5节(文件格式)和第8节(管理命令)中。运用特定故障排除工具的管理员也使用第2节(系统调用)。剩余的章节通常供程序员参考或用于高级管理。
说明:man命令 –K选项执行全文本页面搜索,而不像-k那样仅搜索标题和描述。全文本搜索可能会使用更多系统资源,耗费更多时间。
该案例暂时没有网友评论
✖
案例意见反馈
亲~登录后才可以操作哦!
确定你的邮箱还未认证,请认证邮箱或绑定手机后进行当前操作