一天一命令-命令帮助
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一天一命令-命令帮助相关的知识,希望对你有一定的参考价值。
一天一命令-命令帮助
如何系统的学习一个bash命令:
需求,了解命令的格式,选项,帮助手册,案例,练习,拓展。
想要达到什么效果,有没有这样的命令,命令的格式和使用方法,有什么其他的选项,系统中的完整的帮助手册,常用的选项和案例有哪些,拓展的命令使用方法。
5w1h方法:what,why,when,where,who,how
1.程序自身的帮助文档:/usr/share/doc/cmd-version
2.发行版官方文档:http://www.redhat.com/docs
3.Google Hack搜索
4.slideshare幻灯片:http://www.slideshare.net/
type cmd //查看命令类型,是属于bash内部命令还是外部命令,并显示路径
cmd --version 或者cmd -V //查看命令工具的版本
whatis //显示man帮助页面和简单描述
which //显示文件路径
whereis //查找文件的二进制,源码,man帮助文件路径
hash //外部命令缓存
help cmd 或者cmd --help //内部命令帮助查询
info //多页面显示命令帮助
man //主要的命令帮助手册,推荐使用
type
显示命令的类型是内部还是外部命令
Usage: type [-afptP] name [name ...] -a 显示所有属性,包括alias别名,是内部命令builtin还是外部命令并列出绝对路径 -f 显示文件类型是内部还是外部,并显示路径 -P 大写P,显示命令的绝对路径 -t 显示命令的类型,内部builtin,别名alias,外部file,保留关键字keyword
[执行命令]#type -a ls ls is aliased to `ls -p --color=auto‘ ls is /usr/bin/ls [执行命令]#type ll ll is aliased to `ls -al --color=auto‘ [执行命令]#type -a cd cd is a shell builtin cd is /usr/bin/cd [执行命令]#type -a python python is /usr/bin/python [执行命令]#type -a cd ls pwd cd is a shell builtin cd is /usr/bin/cd ls is aliased to `ls -p --color=auto‘ ls is /usr/bin/ls pwd is a shell builtin pwd is /usr/bin/pwd [执行命令]#type whatis whatis is hashed (/usr/bin/whatis) [执行命令]#type { { is a shell keyword [执行命令]#type [ [ is a shell builtin [执行命令]#type apachectl apachectl is /app/apache25/bin/apachectl
查看命令或软件的版本
[执行命令]#ls --version ls (GNU coreutils) 8.22 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Richard M. Stallman and David MacKenzie. [执行命令]#python -V Python 2.7.5
whatis
显示命令的man帮助页面和功能描述
Usage: whatis [OPTION...] KEYWORD... -r 支持正则表达式regex
[执行命令]#whatis ls ls (1) - list directory contents ls (1p) - list directory contents [执行命令]#whatis ll ll: nothing appropriate. [执行命令]#whatis cd cd (1) - bash built-in commands, see bash(1) cd (1p) - change the working directory [执行命令]#whatis python python (1) - an interpreted, interactive, object-oriented programming language [执行命令]#whatis -r pwd lckpwdf (3) - get shadow password file entry pwd (1) - print name of current/working directory pwd (1p) - return working directory name pwd.h (0p) - password structure pwdx (1) - report current working directory of a process ulckpwdf (3) - get shadow password file entry unix_chkpwd (8) - Helper binary that verifies the password of the current user
which
显示命令的绝对路径,是根据PATH设置的目录进行查找的,不同用户的PATH不同,搜索到的文件内容也不相同
Usage: /usr/bin/which [options] [--] COMMAND [...]
[执行命令]#which -a ls alias ls=‘ls -p --color=auto‘ /usr/bin/ls [执行命令]#which -a ll alias ll=‘ls -al --color=auto‘ /usr/bin/ls [执行命令]#which -a cd /usr/bin/cd [执行命令]#which -a python /usr/bin/python [执行命令]#which apachectl /app/apache25/bin/apachectl
whereis
查找指定命令的二进制程序,源代码和man手册等相关文件路径
Usage: whereis [options] file -b 只搜索二进制文件 -m 只搜索man手册 -s 搜索源代码
[执行命令]#whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz [执行命令]#whereis ll ll: [执行命令]#whereis cd cd: /usr/bin/cd /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz [执行命令]#whereis python python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz [执行命令]#whereis kernel kernel: /usr/lib/kernel /etc/kernel [执行命令]#whereis apachectl apachectl: /app/apache25/bin/apachectl
内部命令帮助 [执行命令]#help pwd pwd: pwd [-LP] Print the name of the current working directory. Options: -L print the value of $PWD if it names the current working directory -P print the physical directory, without any symbolic links By default, `pwd‘ behaves as if `-L‘ were specified. Exit Status: Returns 0 unless an invalid option is given or the current directory cannot be read. 外部命令帮助 [执行命令]#whatis --help Usage: whatis [OPTION...] KEYWORD... -d, --debug emit debugging messages -v, --verbose print verbose warning messages -r, --regex interpret each keyword as a regex -w, --wildcard the keyword(s) contain wildcards -l, --long do not trim output to terminal width -C, --config-file=FILE use this user configuration file -L, --locale=LOCALE define the locale for this search -m, --systems=SYSTEM use manual pages from other systems -M, --manpath=PATH set search path for manual pages to PATH -s, --sections=LIST, --section=LIST search only these sections (colon-separated) -?, --help give this help list --usage give a short usage message -V, --version print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options. Report bugs to [email protected]
man帮助文档
man存放地址:/usr/share/man
man命令的配置文件:c68: /etc/man.conf | c73: /etc/man_db.conf
man章节分类:1.用户命令 2.系统调用 3.C库调用 4.设备文件及特殊文件 5.配置文件格式 6.游戏 7.杂项 8.管理类命令 9.Linux内核API
whatis passwd
man 1 passwd
man 5 passwd
man的显示是使用less命令来实现,操作也一样
向下翻屏:空格,^V,^f,^F
向上翻屏:b,^B
向下翻半屏:d,^D
向上翻半屏:u,^U
向上翻一行:回车,^N,e,^E,j,^J
向下翻一行:y,^Y,^P,k,^K
退出:q
跳转到第n行:n
回到文首:1G
回到文尾:G
向下搜索,不区分字符大小写:/keyword 下一个n;上一个N
向上搜索,不区分大小写:?keyword 下一个n;上一个N
man cmd命令帮助导出到文件且保留原格式
man ls | col -b > ls.txt
到指定位置搜索命令的手册页面并显示:man -M /PATH cmd
#man -aw -M /usr/share/man/ passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man1/sslpasswd.1ssl.gz /usr/share/man/man5/passwd.5.gz #man -aw -M /usr/local/share/man/ passwd 没有 passwd 的手册页条目 //默认只会搜索匹配一层目录,不会递归目录查询 #man -aw -M /usr/local/share/man/zh_CN/ passwd /usr/local/share/man/zh_CN/man5/passwd.5 man -k password //列出所有匹配关键字的man页面列表,使用whatis数据库 man -f passwd //相当于whatis man -w [章节]keyword //打印man帮助文件路径 man -w 5 passwd
其他帮助文档:/usr/share/doc
符号说明:[]:可选内容 <>:必选内容 a|b:二选一 ...:同一内容可出现多次
本文出自 “rackie” 博客,请务必保留此出处http://rackie386.blog.51cto.com/11279229/1935149
以上是关于一天一命令-命令帮助的主要内容,如果未能解决你的问题,请参考以下文章