Linux 终端操作命令
也称Shell命令,是用户与操作系统内核进行交互的命令解释器,它接收用户输入的命令并将其传递给操作系统进行执行,可分为内部命令和外部命令。内部命令是Shell程序的一部分,而外部命令是独立于Shell的可执行程序。
内部命令
内部命令,实际上是shell程序的一部分,由shell程序识别并在shell程序内部完成运行,通常在Linux系统加载运行时shell就被加载并驻留在系统内存中。内部命令是写在bash源码里面的,因为解析内部命令shell不需要创建子进程,其执行速度比外部命令快。比如:alias, break, cd, echo, exit, pwd 等。
外部命令
外部命令是bash shell之外的程序,也并不是shell的一部分。外部命令位于/bin,/sbin, /usr/bin 或 /usr/sbin 等系统目录中。外部命令是Linux系统中的实用程序部分,因为实用程序的功能通常都比较强大,所以其包含的程序量也会很大,在系统加载时并不随系统一起被加载到内存中,而是在需要时才将其调用内存。通常外部命令的实体并不包含在shell中,但是其命令执行过程是由shell程序控制的。比如: awk, grep, ping,tar, vi 等。 除Linux系统自带的外部命令,通常需要安装对应的程序包才能使用,内部命令之外的所有可执行程序都可以被认作为外部命令。
内外部命令区别
内部命令在系统启动时就调入内存,是常驻内存的,所以执行效率高。
外部命令是系统的软件功能,用户需要时才从硬盘中读入内存,执行速度比内部命令慢。
内部命令列表
help命令可以列出所有内部命令:
hann@HannYang:~$ help
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
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 history -anrw [filename]>
(( expression )) if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMAN>
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs -x command [args]
: kill [-s sigspec | -n signum | -sigspec] pid | jobspec .>
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-d delim] [-n count] [-O origin] [-s count] [-t>
bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u > 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]...) COMMANDS ;;]... esa> read [-ers] [-a array] [-d delim] [-i text] [-n nchars] >
cd [-L|[-P [-e]] [-@]] [dir] readarray [-d delim] [-n count] [-O origin] [-s count] [>
command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] or readonly -p
compgen [-abcdefgjksuv] [-o option] [-A action] [-G globp> return [n]
complete [-abcdefgjksuv] [-pr] [-DEI] [-o option] [-A act> select NAME [in WORDS ... ;] do COMMANDS; done
compopt [-o|+o option] [-DEI] [name ...] set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
continue [n] shift [n]
coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
declare [-aAfFgilnrtux] [-p] [name[=value] ...] source filename [arguments]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [jobspec ... | pid ...] test [expr]
echo [-neE] [arg ...] time [-p] pipeline
enable [-a] [-dnps] [-f filename] [name ...] times
eval [arg ...] trap [-lp] [[arg] signal_spec ...]
exec [-cl] [-a name] [command [arguments ...]] [redirecti> true
exit [n] type [-afptP] name [name ...]
export [-fn] [name[=value] ...] or export -p typeset [-aAfFgilnrtux] [-p] name[=value] ...
false ulimit [-SHabcdefiklmnpqrstuvxPT] [limit]
fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [c> umask [-p] [-S] [mode]
fg [job_spec] unalias [-a] name [name ...]
for NAME [in WORDS ... ] ; do COMMANDS; done unset [-f] [-v] [-n] [name ...]
for (( exp1; exp2; exp3 )); do COMMANDS; done until COMMANDS; do COMMANDS; done
function name { COMMANDS ; } or name () { COMMANDS ; } variables - Names and meanings of some shell variables
getopts optstring name [arg] wait [-fn] [id ...]
hash [-lr] [-p pathname] [-dt] [name ...] while COMMANDS; do COMMANDS; done
help [-dms] [pattern ...] { COMMANDS ; }
通过整理以上内容,得到 68 个命令、函数、变量以及控制指令:
1 | alias | alias [-p] [name[=value] ... ] |
2 | bg | bg [job_spec ...] |
3 | bind | bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u > |
4 | break | break [n] |
5 | builtin | builtin [shell-builtin [arg ...]] |
6 | caller | caller [expr] |
7 | case | case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esa> |
8 | cd | cd [-L|[-P [-e]] [-@]] [dir] |
9 | command | command [-pVv] command [arg ...] |
10 | compgen | compgen [-abcdefgjksuv] [-o option] [-A action] [-G globp> |
11 | complete | complete [-abcdefgjksuv] [-pr] [-DEI] [-o option] [-A act> |
12 | compopt | compopt [-o|+o option] [-DEI] [name ...] |
13 | continue | continue [n] |
14 | coproc | coproc [NAME] command [redirections] |
15 | declare | declare [-aAfFgilnrtux] [-p] [name[=value] ...] |
16 | dirs | dirs [-clpv] [+N] [-N] |
17 | disown | disown [-h] [-ar] [jobspec ... | pid ...] |
18 | echo | echo [-neE] [arg ...] |
19 | enable | enable [-a] [-dnps] [-f filename] [name ...] |
20 | eval | eval [arg ...] |
21 | exec | exec [-cl] [-a name] [command [arguments ...]] [redirecti> |
22 | exit | exit [n] |
23 | export | export [-fn] [name[=value] ...] or export -p |
24 | false | false |
25 | fc | fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [c> |
26 | fg | fg [job_spec] |
27 | for | for NAME [in WORDS ... ] ; do COMMANDS; done for (( exp1; exp2; exp3 )); do COMMANDS; done |
28 | function | function name { COMMANDS ; } or name () { COMMANDS ; } |
29 | getopts | getopts optstring name [arg] |
30 | hash | hash [-lr] [-p pathname] [-dt] [name ...] |
31 | help | help [-dms] [pattern ...] |
32 | history | history [-c] [-d offset] [n] or history -anrw [filename]> |
33 | if | if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMAN> |
34 | jobs | jobs [-lnprs] [jobspec ...] or jobs -x command [args] |
35 | kill | kill [-s sigspec | -n signum | -sigspec] pid | jobspec .> |
36 | let | let arg [arg ...] |
37 | local | local [option] name[=value] ... |
38 | logout | logout [n] |
39 | mapfile | mapfile [-d delim] [-n count] [-O origin] [-s count] [-t> |
40 | popd | popd [-n] [+N | -N] |
41 | printf | printf [-v var] format [arguments] |
42 | pushd | pushd [-n] [+N | -N | dir] |
43 | pwd | pwd [-LP] |
44 | read | read [-ers] [-a array] [-d delim] [-i text] [-n nchars] > |
45 | readarray | readarray [-d delim] [-n count] [-O origin] [-s count] [> |
46 | readonly | readonly [-aAf] [name[=value] ...] or readonly -p |
47 | return | return [n] |
48 | select | select NAME [in WORDS ... ;] do COMMANDS; done |
49 | set | set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] |
50 | shift | shift [n] |
51 | shopt | shopt [-pqsu] [-o] [optname ...] |
52 | source | source filename [arguments] |
53 | suspend | suspend [-f] |
54 | test | test [expr] |
55 | time | time [-p] pipeline |
56 | times | times |
57 | trap | trap [-lp] [[arg] signal_spec ...] |
58 | true | true |
59 | type | type [-afptP] name [name ...] |
60 | typeset | typeset [-aAfFgilnrtux] [-p] name[=value] ... |
61 | ulimit | ulimit [-SHabcdefiklmnpqrstuvxPT] [limit] |
62 | umask | umask [-p] [-S] [mode] |
63 | unalias | unalias [-a] name [name ...] |
64 | unset | unset [-f] [-v] [-n] [name ...] |
65 | until | until COMMANDS; do COMMANDS; done |
66 | variables | variables - Names and meanings of some shell variables |
67 | wait | wait [-fn] [id ...] |
68 | while | while COMMANDS; do COMMANDS; done |
内部命令分类
自己动手分类吧,具体分类明天继续......