学会用Linux的帮助命令
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了学会用Linux的帮助命令相关的知识,希望对你有一定的参考价值。
命令 | 解释 |
---|---|
type [ 命令 ] | 判断是内部命令 or 外部命令 |
--help | 外部命令 |
help | 只针对系统内部命令 |
man [] | 内容清晰、详细,在线文档,支持搜索( /name ) man [ 章节 ] [name] |
info [] | 太详细 |
/usr/share/doc | 存放帮助文档,在与软件同名的目录下有所有软件的使用文档 |
man和—help以及help的区别
man命令
系统中会有单独的man文件,就是说,如果系统没有安装对应man文件,哪怕命令完全正常,man都没结果(同样,只要安装了man文件,哪怕没命令,也可以得到一大堆东西)。
--help参数 将会显示可执行程序自带的信息,这些信息是嵌入到程序本身的,所以--help信息较简短。
help命令 是选项帮助命令,顾名思义 你可以把单独某个命令的某个选项列出来,方便快捷很多,省去了man当中查找的繁琐,但是help只支持shell的内部命令。内部命令即存储在shell内部可以直接调用的一些简单命令,比如说echo,cd,pwd等。
type
type命令用来显示指定命令的类型,判断给出的指令是内部指令还是外部指令。
语法
type(选项)(参数)
选项
-t:输出“file”、“alias”或者“builtin”,分别表示给定的指令为“外部指令”、“命令别名”或者“内部指令”;
-p:如果给出的指令为外部指令,则显示其绝对路径;
-a:在环境变量“PATH”指定的路径中,显示给定指令的信息,包括命令别名。 参数 指令:要显示类型的指令。
参数
关键字:指定要搜索帮助的关键字
命令类型
alias:别名
keyword:关键字,Shell保留字
function:函数,Shell函数
builtin:内建命令,Shell内建命令
file:文件,磁盘文件,外部命令
unfound:没有找到
尝试几个命令man,ls,touch,echo,cat
[booboo@rhel7 ~]$ type man
man is /bin/man
[booboo@rhel7 ~]$ type ls
ls is aliased to `ls –color=auto
[booboo@rhel7 ~]$ which ls
alias ls=ls --color=auto
/bin/ls
[booboo@rhel7 ~]$ type touch
touch is hashed (/bin/touch)
[booboo@rhel7 ~]$ type echo
echo is a shell builtin
[booboo@rhel7 ~]$ type cat
cat is hashed (/bin/cat)
内置命令一般显示为“is a shell builtin ”
除了内置命令外,其他命令都是通过某个安装包安装生成的可执行文件
接下来我们一起看看这些命令都是什么软件生成的
[booboo@rhel7 ~]$ rpm -qf /bin/man
man-db-2.6.3-9.el7.x86_64
[booboo@rhel7 ~]$ rpm -qf /bin/ls
coreutils-8.22-11.el7.x86_64
[booboo@rhel7 ~]$ rpm -qf /bin/touch
coreutils-8.22-11.el7.x86_64
[booboo@rhel7 ~]$ rpm -qf /bin/cat
coreutils-8.22-11.el7.x86_64
[booboo@rhel7 ~]$ type if
if is a shell keyword
--help 参数
--help参数是大所数命令自带的选项,用于查看使用帮助。
[booboo@rhel7 ~]$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE scale sizes by SIZE before printing them; e.g.,
--block-size=M prints sizes in units of
1,048,576 bytes; see SIZE format below
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last
modification of file status information);
with -l: show ctime and sort by name;
otherwise: sort by ctime, newest first
-C list entries by columns
--color[=WHEN] colorize the output; WHEN can be never, auto,
or always (the default); more info below
-d, --directory list directories themselves, not their contents
-D, --dired generate output designed for Emacs dired mode
-f do not sort, enable -aU, disable -ls --color
help
help只支持shell的内部命令。内部命令即存储在shell内部可以直接调用的一些简单命令,例如cd,echo,help等。
help(选项)(参数) -s:输出短格式的帮助信息。仅包括命令格式。
[booboo@rhel7 ~]$ type cd
cd is a shell builtin
[booboo@rhel7 ~]$ help cd
cd: cd [-L|[-P [-e]]] [dir]
Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the
HOME shell variable.
The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.
If the directory is not found, and the shell option `cdable_vars is set,
the word is assumed to be a variable name. If that variable has a value,
its value is used for DIR.
Options:
-L force symbolic links to be followed
-P use the physical directory structure without following symbolic
links
-e if the -P option is supplied, and the current working directory
cannot be determined successfully, exit with a non-zero status
The default is to follow symbolic links, as if `-L were specified.
Exit Status:
Returns 0 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.
[booboo@rhel7 ~]$ type touch
touch is hashed (/bin/touch)
[booboo@rhel7 ~]$ type echo
echo is a shell builtin
[booboo@rhel7 ~]$ help echo
echo: echo [-neE] [arg ...]
man
man命令是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助、配置文件帮助和编程帮助等信息。
语法
man(选项)(参数)
选项
-a:在所有的man帮助手册中搜索;
-f:等价于whatis指令,显示给定关键字的简短描述信息;
-P:指定内容时使用分页程序;
-M:指定man手册搜索的路径。
参数
数字:指定从哪本man手册中搜索帮助
关键字:指定要搜索帮助的关键字
例如输入man ls,它会在左上角显示“ECHO(1)”“ECHO”代表手册名称;“(1)”代表 表示该手册位于第一节章1)”表示该手册位于第一节章,同样,我们输man ifconfig它会在最左上角显示“IFCONFIG(8)”。也可以这样输入命令:“man [章节号] 手册名称”。 man是按照手册的章节号的顺序进行搜索的,比如: man sleep 只会显示sleep命令的手册,如果想查看库函数sleep,就要输入: man 3 sleep
[booboo@rhel7 ~]$ man echo|cat
ECHO(1) User Commands ECHO(1)
#此处“ECHO”代表手册名称;“(1)”代表 表示该手册位于第一节章
NAME
echo - display a line of text
SYNOPSIS
echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION
DESCRIPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
--help display this help and exit
--version
output version information and exit
If -e is in effect, the following sequences are recognized:
\\\\ backslash
\\a alert (BEL)
\\b backspace
\\c produce no further output
\\e escape
\\f form feed
\\n new line
\\r carriage return
\\t horizontal tab
\\v vertical tab
\\0NNN byte with octal value NNN (1 to 3 digits)
\\xHH byte with hexadecimal value HH (1 to 2 digits)
NOTE: your shell may have its own version of echo, which usually
supersedes the version described here. Please refer to your shells
documentation for details about the options it supports.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report echo translation bugs to <http://translationproject.org/team/>
AUTHOR
Written by Brian Fox and Chet Ramey.
COPYRIGHT
Copyright © 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.
SEE ALSO
The full documentation for echo is maintained as a Texinfo manual. If
the info and echo programs are properly installed at your site, the
command
info coreutils echo invocation
should give you access to the complete manual.
GNU coreutils 8.22 January 2014 ECHO(1)
以上是关于学会用Linux的帮助命令的主要内容,如果未能解决你的问题,请参考以下文章