文章目录
- man
- info
- 1. Get information from specific sections of man pages using -s option
- 2. Search information through wild-cards using -w option
- 3. Search information through regular expressions using -r option
- 4. Disable trimmed output using -l option
- 5. Restrict search up to specified path using -M option
- 6. Locate binaries using -b option
- 7. Locate man pages for a command using -m option
- 8. Locate source of a command using -s option
- 9. Locate unusual entries using -u option
- 10. Locate binaries in a specified path using -B option
- 11. Locate man pages with limited scope using -M option
reference link
reference link:
7 Ways to Get Command Line Help on Linux
关于WSL
- (windows sub-system linux)
- 在linux子系统中,您安装的发行版可能没有自带安装以下命令.
如果shell提示您找不到命令,可以安装他们
您自行安装:
sudo apt install <theCommandYouNeed>
或sudo yum install <theCommandYouNeed>
eg.安装man:
sudo apt install man
windows terminal+WSL
借助wsl(windows sub-system linux)学习linux命令
aprospos
想做一件事不知道用什么命令?
用aprospos <yourKeyword>
可以帮你查找相关命令
例如,以复制文件这一任务,查找可以完成相关任务的相关命令.
比如我们从中知道了,我们需要使用cp命令
whatis
获取某个(已知名称的)命令的简介(一行)
man和info 不是什么都查的到,但是大多数情况可以查到
(非build-in command)情况下可以查到
linux_man_wildcard/whatis/正则匹配/匹配以keyword开头的条目
使用
apropos
检索man手册,是利用手册的好方法,但有时候,apropos默认返回的结果太多,不利于定位
whatis &apropos &man
三者对比:
# cxxu @ CxxuWin11 in ~/.config/cheat [19:07:35] C:16
$ whatis whatis
whatis (1) - display one-line manual page descriptions
# cxxu @ CxxuWin11 in ~/.config/cheat [19:07:39]
$ whatis apropos
apropos (1) - search the manual page names and descriptions
# cxxu @ CxxuWin11 in ~/.config/cheat [19:08:09]
$ whatis man
man (1) - an interface to the system reference manuals
man (7) - macros to format man pages
man (1posix) - display system documentation
- 其中,
man -k
近似于apropos
-
man -f
近似于whatis
(但是不起完全一样,特别是使用某些额外的选项时)
whatis -w [keyward_wildcard] /-r [regex]
-r, --regex
Interpret each name as a regular expression. If a name matches any part of a page name, a match will be made. This option causes whatis to be somewhat slower due to
the nature of database searches.
-w, --wildcard
Interpret each name as a pattern containing shell style wildcards. For a match to be made, an expanded name must match the entire page name. This option causes whatis
to be somewhat slower due to the nature of database searches.
whatis -w
# cxxu @ CxxuWin11 in ~/.config/cheat [18:57:37]
$ whatis -w file*
FILE (3) - overview of system data types
file (1) - determine file type
file (1posix) - determine file type
file-hierarchy (7) - File system hierarchy overview
File::FcntlLock (3pm) - File locking with fcntl(2)
File::FcntlLock::Inline (3pm) - File locking with fcntl(2)
File::FcntlLock::Pure (3pm) - File locking with fcntl(2)
File::FcntlLock::XS (3pm) - File locking with fcntl(2)
filefrag (8) - report on file fragmentation
filefuncs (3am) - provide some file related functionality to gawk
fileno (3) - check and reset stream status
fileno_unlocked (3) - nonlocking stdio functions
filesystems (5) - Linux filesystem types: ext, ext2, ext3, ext4, hpfs
whatis -r
# cxxu @ CxxuWin11 in ~/.config/cheat [19:13:36] C:16
$ whatis -r ^file
FILE (3) - overview of system data types
file (1) - determine file type
file (1posix) - determine file type
file-hierarchy (7) - File system hierarchy overview
File::FcntlLock (3pm) - File locking with fcntl(2)
File::FcntlLock::Inline (3pm) - File locking with fcntl(2)
File::FcntlLock::Pure (3pm) - File locking with fcntl(2)
File::FcntlLock::XS (3pm) - File locking with fcntl(2)
filefrag (8) - report on file fragmentation
filefuncs (3am) - provide some file related functionality to gawk
fileno (3) - check and reset stream status
fileno_unlocked (3) - nonlocking stdio functions
filesystems (5) - Linux filesystem types: ext, ext2, ext3, ext4, hpfs,
使用man命令来达到相同的效果
# cxxu @ CxxuWin11 in ~/.config/cheat [18:57:31]
$ man -f file* -w
FILE (3) - overview of system data types
file (1) - determine file type
file (1posix) - determine file type
file-hierarchy (7) - File system hierarchy overview
File::FcntlLock (3pm) - File locking with fcntl(2)
File::FcntlLock::Inline (3pm) - File locking with fcntl(2)
File::FcntlLock::Pure (3pm) - File locking with fcntl(2)
File::FcntlLock::XS (3pm) - File locking with fcntl(2)
filefrag (8) - report on file fragmentation
filefuncs (3am) - provide some file related functionality to gawk
fileno (3) - check and reset stream status
fileno_unlocked (3) - nonlocking stdio functions
filesystems (5) - Linux filesystem types: ext, ext2, ext3, ext4, hpfs, iso9660
oh-my-zsh 框架
# cxxu @ CxxuWin11 in ~/.config/cheat [19:05:44] C:130
$ man file file File::FcntlLock File::FcntlLock::Pure filefrag file-hierarchy fileno_unlocked
FILE File::FcntlLock::Inline File::FcntlLock::XS filefuncs fileno filesystems
man
- 获取命令的稍加详细的说明(完整的选项,但是选项描述简单)
- 主要强调一下搜索功能和翻页快捷键
搜索通过在man返回结果的页面中使用/keywoard
进行搜索(支持正则表达式),类似与vim
了解man 的方式
man man
应当读一遍过去
man man
的返回结果中的EXAMPLES部分:
man获取命令的使用示例:
有些命令带有示例,但是未必通俗易懂,本人经常还是通过搜索引擎搜索更入门的讲解
- 您可以尝试在man中搜索examples(但不是每个命令都有给出EXMAPLES)
您可以通过man的搜索功能/^EXAMPLE
来跳转到用法示例部分:
使用搜索功能的时候,您可以将窗口收窄一些,这样高亮的地方会更容易进入您的视线
此外,搜索表达式键入并enter之后,您可以通过(n
来向后查找(更准确的说法是正向查找),而(N
可以用来反向查找)(这在您遇到not find...
的时候使用者两个键尝试往不同方向来搜索内容
获取在线文档
/https:
但是一般配合info
命令可以获得命令的全部帮助
info
- info将一般都会给出命令的示例,不过info的使用风格和man较为不同
- info的内容更有层次感(每个命令会其专属的目录(做成查链接大纲)
- 您可以通过tab在这些大纲/菜单(menu)上跳转,通过enter键来进入大纲对应的内容
例如,我执行info sed
/example
- 可以通过
info info
命令来查看info
文档的用法和帮助说明. - 通过键入
H
来获取快捷键列表
info基本的滚动和跳转快捷键说明.
- 黑色的信息(Node)表示其上方的内容是关于什么的.
跳转到上一个出现的地方/下一个出现的地方
有时info
提供比man
更加详细的结果.
在搜索页面中的内容时,您同样可以使用正则表达式来搜索
做一个对比:
info cp
man cp
help
- Note: Only built-in commands can be used with the help command.
- The help command only works with the
bash
shell. - Another useful utility for getting help on the command-line is the help command.
- Use it to get a brief description of a specific built-in command.
用户查询linux内置命令的简单介绍
注意,zsh可能支持,您或许需要在bash下执行该命令.
The Help Argument(<commandName> --help
)
-
<commandName> --help
这一命令格式不限于bash,而且不限于shell自带命令,所以它较help <commandName>
这种格式更有用
history
Recalling Commands:
The Linux terminal allows you to list commands that you have run earlier. Use the history command to show a list of previously run commands.
- To re-run a command from the history list simply type ! followed by the number of the command. For example to re-run the command number 9 in the list.
Ctrl+R
sometimes,the
ctrl+r
may more useful and powerful.
Another way to recall commands is to use the Ctrl + R keyboard shortcut within the terminal window then enter the keyword you are looking for. You can then use the CTRL + R to cycle through all previously run commands containing the keyword you provided.
build-in command
Linux_ Which /Whatis/Whereis
reference
- This Linux tutorial will explain the three “W” commands. The three “W”s are whatis, whereis and which commands.
I. Linux whatis Command
- Whatis command is helpful to
get brief information about Linux commands or functions
.
- Whatis command displays man page
single line description
for command thatmatches string passed as a command line argument to whatis command
. - Whatis command searches for string in its index databases which is
maintained by mandb program
. - Whatis command picks short description of
NAME section of man page
of command that matches to input given to the whatis command.
- Whatis provides several command line options to help user in getting
brief information of specific Linux commands
as per their need or interest.
Syntax:
$ whatis [-options]
For example, here is the output of whatis command, when it is run without any option.
$ whatis write
write (1) - send a message to another user
write (2) - write to a file descriptor
It displays brief information about “write” from man pages.
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Brv4QCmX-1648100585512)(image/whatis_where_/1648098763683.png)]
1. Get information from specific sections of man pages using -s option
If we want to get Linux command information from specific section of man pages, then we can provide sections list using “-s or —sections or –section” option. It will restrict whatis command to display brief information from specified man page section only.
$ whatis -s "1","2" open
open (1) - start a program on a new virtual terminal (VT).
open (2) - open and possibly create a file or device
It displays open command and function brief information from man page sections 1 and 2.
$ whatis -s "2" open
open (2) - open and possibly create a file or device
It displays open function brief information from man page section 2.
2. Search information through wild-cards using -w option
If we want to search Linux commands or functions information using wild card, then whatis command gives “-w or –wildcard” option. It will make your search specific as per user’s need.
$ whatis -w 'ab*'
abort (3) - cause abnormal process termination
abs (3) - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab”.
$ whatis -w 'ab?'
abs (3) - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab” and followed by any single character.
3. Search information through regular expressions using -r option
If we want to search Linux commands or functions information using regular expressions, then whatis command gives “-r or –regex” option. It will give flexibility to customize your search for Linux commands or functions throughout the Linux system.
$ whatis -r '^ab'
abort (3) - cause abnormal process termination
abs (3) - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab”.
$ whatis -r 'ab$'
anacrontab (5) - configuration file for anacron
baobab (1) - A graphical tool to analyse disk usage
crontab (1) - maintain crontab files for individual users (Vixie Cron)
crontab (5) - tables for driving cron
fstab (5) - static information about the filesystems
inittab (5) - init daemon configuration
swab (3) - swap adjacent bytes
tc-stab (8) - Generic size table manipulations
It displays brief information of Linux commands or functions which ends with “ab”.
4. Disable trimmed output using -l option
Generally whatis command trims long output of Linux commands or functions information to avoid “Not good” output display on terminal that is going beyond screen. To allow whatis command to show complete output on screen, “-l or –long” option can be used.
$ whatis ssh-import-id
ssh-import-id (1) - retrieve one or more public keys from a public keyserver (Launchpad.net by default) and append them to the current user's authorized_keys file (or some other specifie...
It displays trimmed output of brief information of Linux command.
$ whatis -l ssh-import-id
ssh-import-id (1) - retrieve one or more public keys from a public keyserver (Launchpad.net by default) and append them to the current user's authorized_keys file (or some other specified file)
It displays complete output of brief information of Linux command.
5. Restrict search up to specified path using -M option
By default, whatis command uses $MANPATH environment variable. But whatis provides “-M or –manpath” option to restrict search up to specified path of man pages.
$ whatis -M /usr/share/man hexdump
hexdump (1) - ASCII, decimal, hexadecimal, octal dump
It displays brief information of Linux hexdump command from man pages available at path /usr/share/man.
$ whatis -M /usr/man hexdump
hexdump: nothing appropriate.
It could not find brief information of Linux hexdump command from specified path /usr/man.
II. Linux whereis Command
-
Whereis
command is helpful tolocate
- binary,
- source,
-
manual pages of commands
in the Linux system.
- It is very simple utility and provides several options which are given below with examples.
Syntax:
$ whereis [-options]
For example, whereis command is run without any option.
$ whereis open
open: /bin/open /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz
- It locates
-
binary
, -
source and man pages of “open” command
and -
paths
(where (binary, man pages of open command) is available) in the system.
6. Locate binaries using -b option
If we want to locate binary of Linux command, use “-b” option.
$ whereis -b whereis
whereis: /usr/bin/whereis /usr/bin/X11/whereis
It locates binary of “whereis” command and displays paths where binary of command is available in the system.
7. Locate man pages for a command using -m option
If we want to locate man page of Linux command, use “-m” option.
$ whereis -m whereis
whereis: /usr/share/man/man1/whereis.1.gz
It locates man page of “whereis” command and displays path where man page of command is available in the system.
8. Locate source of a command using -s option
If we want to locate source of Linux command, use “-s” option.
$ whereis -s whereis
whereis:
It locates source of “whereis” command, but source of “whereis” command does not exist in the system, so it did not display path for source of command in the system.
9. Locate unusual entries using -u option
This option is something different that searches for unusual entries. These entries are those command whose source, binary or man page does not exist in the system as per options “[-bms]” specified along with “–u”.
$ whereis -m -u wcgrep
wcgrep:
It checks if specified command (i.e. wcgrep) man page does not exist in the system. Whereis command with options “-m and -u” locates for the commands in the system whose man page does not exist.
$ whereis -m -u grep
$
Here, whereis command with same options is applied on “grep” command whose man page exists in the system, so whereis returned nothing and exits normally.
10. Locate binaries in a specified path using -B option
If user wants to search for binary and wants to limit the scope of search for whereis command up to specified path, then use “-B” option.
$ whereis -B /bin -f for_loop
for_loop: /bin/for_loop
It locates binary of “for_loop” user program from path “/bin”.
$ whereis -B /usr -f open
open: /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz
If open command’s binary is not found at specified path, then it is not shown but whereis command by default searches for other types (i.e. man page and source) of specified command (i.e. open) and displays them if found.
11. Locate man pages with limited scope using -M option
If user wants to search for man pages and wants to limit the scope of search for whereis command up to specified path, then use “-M” option.
$ whereis -M /usr/share/man/man1 -f open
open: /bin/open /usr/share/man/man1/open.1.gz
$ whereis -M /usr/share/man/man2 -f open
open: /bin/open /usr/share/man/man2/open.2.gz
$ whereis -M /usr/share/man/man3 -f open
open: /bin/open
Here, it is observed that whereis command is displaying man page of “open” command which is available in specified path only. But, whereis command by default searches for other types (i.e. binary and source) of specified command (i.e. open) and displays them if found.
III. Linux which Command
-
Which
command is very small and simple command to locateexecutables
in the system.
- It allows user to pass
several command names as arguments
to gettheir paths in the system
. - “which” commands searches the path of executable in
system paths
set in $PATHenvironment variable.
Syntax:
$ which [-option]
For example,
$ which ls gdb open grep
/bin/ls
/usr/bin/gdb
/bin/open
/bin/grep
It locates command names – “ls”, “gdb”, “open” and “grep” specified as arguments to “which” command and displays paths of each executable where it exists in the system.
12. Display all the paths using -a option
“which” command gives option “-a” that displays all paths of executable matching to argument.
$ which echo
/usr/sbin/echo
默认情况下,只返回第一个找到的结果,如果要返回找到的所有结果,使用
-a
选项
- Above will search display the executable “echo” from all paths set in
$PATH
environment variable and displays the first path where echo executable is found. - It may be case that executable is placed at other paths of $PATH environment variable as well.
- To get all paths where executable is present in the system, “-a” option can be used.
$ which -a echo
/usr/sbin/echo
/bin/echo
build-in command list
reference
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.
A star (*) next to a name means that the command is disabled.
job_spec [&] history [-c] [-d offset] [n] or hist>
(( expression )) if COMMANDS; then COMMANDS; [ elif C>
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
: kill [-s sigspec | -n signum | -sigs>
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-n count] [-O origin] [-s c>
bind [-lpvsPVS] [-m keymap] [-f filen> popd [-n] [+N | -N]
break [n] printf [-v var] format [arguments]
builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir]
caller [expr] pwd [-LP]
case WORD in [PATTERN [| PATTERN]...)> read [-ers] [-a array] [-d delim] [->
cd [-L|-P] [dir] readarray [-n count] [-O origin] [-s>
command [-pVv] command [arg ...] readonly [-af] [name[=value] ...] or>
compgen [-abcdefgjksuv] [-o option] > return [n]
complete [-abcdefgjksuv] [-pr] [-DE] > select NAME [in WORDS ... ;] do COMM>
compopt [-o|+o option] [-DE] [name ..> set [--abefhkmnptuvxBCHP] [-o option>
continue [n] shift [n]
coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
declare [-aAfFilrtux] [-p] [name[=val> source filename [arguments]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [jobspec ...] test [expr]
echo [-neE] [arg ...] time [-p] pipeline
enable [-a] [-dnps] [-f filename] [na> times
eval [arg ...] trap [-lp] [[arg] signal_spec ...]
exec [-cl] [-a name] [command [argume> true
exit [n] type [-afptP] name [name ...]
export [-fn] [name[=value] ...] or ex> typeset [-aAfFilrtux] [-p] name[=val>
false ulimit [-SHacdefilmnpqrstuvx] [limit>
fc [-e ename] [-lnr] [first] [last] o> umask [-p] [-S] [mode]
fg [job_spec] unalias [-a] name [name ...]
for NAME [in WORDS ... ] ; do COMMAND> unset [-f] [-v] [name ...]
for (( exp1; exp2; exp3 )); do COMMAN> until COMMANDS; do COMMANDS; done
function name { COMMANDS ; } or name > variables - Names and meanings of so>
getopts optstring name [arg] wait [id]
hash [-lr] [-p pathname] [-dt] [name > while COMMANDS; do COMMANDS; done
help [-dms] [pattern ...] { COMMANDS ; }
bash&zsh
由于oh-my-zsh 框架的出现,我平时用zsh比较多
但是某些命令是shell内建命令,例如
在bash下执行:
┌──(cxxu_kali㉿CxxuWin11)-[~]
└─$ help alias
alias: alias [-p] [name[=value] ... ]
Define or display aliases.
Without arguments, `alias' prints the list of aliases in the reusable
form `alias NAME=VALUE' on standard output.
Otherwise, an alias is defined for each NAME whose VALUE is given.
A trailing space in VALUE causes the next word to be checked for
alias substitution when the alias is expanded.
Options:
-p print all defined aliases in a reusable format
Exit Status:
alias returns true unless a NAME is supplied for which no alias has been
defined.
zsh可能无法获取上述的帮助
在zsh下执行
cxxu_kali➜~» which alias [19:25:56]
alias: shell built-in command
cxxu_kali➜~» which cd [19:26:09]
cd: shell built-in command
cxxu_kali➜~» which ls [19:26:16]
ls: aliased to ls --color=tty
cxxu_kali➜~» which pwd [19:26:20]
pwd: shell built-in command
cxxu_kali➜~» which cwd
获取build-in command 帮助
您可以在bash下执行help BuildInCommandName
例如:
bash
help alias
help cd