当前位置:首页 >> 信息与通信 >>

01.Shell命令学习笔记


?登陆服务器时输入 telnet 192.168.0.23

各个 shell 可互相切换
ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$


一、注意事项
命令和参数之间必需用空格隔开,参数和参数之间也必需用空格隔开。

/> 一行不能超过256个字符;大小写有区分。


二、特殊字符含义
文件名以“.”开头的都是隐藏文件/目录,只需在文件/目录名前加“.”就可隐藏它。
~ 表示主目录。
. 当前目录(一个点)。
.. 上一级目录(两个点)。
; 多个命令一起用。
> >> 输出重定向 。将一个命令的输出内容写入到一个文件里面。如果该文件存在, 就将该文件的内容覆盖;
如果不存在就先创建该文件, 然后再写入内容。
输出重定向,意思就是说,将原来屏幕输出变为文件输出,即将内容输到文件中。
< << 输入重定向。 本来命令是通过键盘得到输入的,但是用小于号,就能够使命令从文件中得到输入。
\ 表示未写完,回车换行再继续。
* 匹配零个或者多个字符。
? 匹配一个字符。
[] 匹配中括号里的内容[a-z][A-Z][0-9]。
! 事件。
!! 执行最近一次的命令
$ 取环境变量的值。
| 管道。把前一命令的输出作为后一命令的输入,把几个命令连接起来。
|经常跟tee连用,tee 把内容保存到文档并显示出来。


三、通用后接命令符
-a 所有(all)。
-e 所有(every),比a更详细。
-f 取消保护。
-i 添加提示。
-p 强制执行。
-r 目录管理。

分屏显示的中途操作
空格<space> 继续打开下一屏;
回车<return> 继续打开下一行;
b 另外开上一屏;
f 另外开下一屏;
h 帮助;
q或Ctrl+C 退出;
/字符串 从上往下查找匹配的字符串;
?字符串 从下往上查找匹配的字符串;
n 继续查找。

四、退出命令
exit 退出; DOS内部命令 用于退出当前的命令处理器(COMMAND.COM) 恢复前一个命令处理器。
Ctrl+d 跟exit一样效果,表中止本次操作。
logout 当csh时可用来退出,其他shell不可用。

clear 清屏,清除(之前的内容并未删除,只是没看到,拉回上面可以看回)。相当与DOS下的cls


五、目录管理命令
pwd 显示当前所在目录,查看当前所在目录的完整路径(绝对路径)。
cd 进入某目录,显示或改变当前目录。
cd回车/cd ~ 都是回到自己的主目录。
cd . 当前目录(空格再加一个点)。
cd .. 回到上一级目录(空格再加两个点)。 cd ../.. 向上两级。
cd /user/s0807 从绝对路径去到某目录。
cd ~/s0807 直接进入主目录下的某目录(“cd ~"相当于主目录的路径的简写)。
ls 查看目录或者文件的属性,列举出任一目录下面的文件
用法 ls [-aAbcCdeEfFghHilLmnopqrRstux1@] [file...]
ls /etc/ 显示某目录下的所有文件和目录,如etc目录下的。
ls -l (list)列表显示文件(默认按文件名排序),
显示文件的权限、硬链接数(即包含文件数,普通文件是1,目录1+)、用户、组名、大小、修改日期、文件名。
ls -t (time)按修改时间排序,显示目录和文件。
ls -lt 是“-l”和“-t”的组合,按时间顺序显示列表。
ls -F 显示文件类型,目录“/ ”结尾;可执行文件“*”结尾;文本文件(none),没有结尾。
ls -R 递归显示目录结构。即该目录下的文件和各个副目录下的文件都一一显示。
ls -a 显示所有文件,包括隐藏文件。

文件权限
r 读权限。对普通文件来说,是读取该文件的权限;对目录来说,是获得该目录下的文件信息。
w 写权限。对文件,是修改;对目录,是增删文件与子目录。
(注 删除没有写权限的文件可以用 rm -f ,这是为了操作方便,是人性化的设计)。
x 执行权限;对目录,是进入该目录
- 表示没有权限
形式 - rw- r-- r--
其中 第一个是文件类型(-表普通文件,d表目录(directory),l表软链接文件(link))
第2~4个是属主,生成文件时登录的人,权限最高,用u表示(user)
第5~7个是属组,系统管理员分配的同组的一个或几个人,用g表示(group)
第8~10个是其他人,除属组外的人,用o表示(other)
所有人,包括属主、属组及其他人,用a表示(all)

chmod 更改权限;
用法 chmod [-fR] <绝对模式> 文件 ...
chmod [-fR] <符号模式列表> 文件 ...
其中 <符号模式列表> 是一个用逗号分隔的表 [ugoa]{+|-|=}[rwxXlstugo]
chmod u+rw 给用户加权限。同理,u-rw也可以减权限。
chmod u=rw 给用户赋权限。与加权限不一样,赋权限有覆盖的效果。
主要形式有如下几种
chmod u+rw chmod u=rw
chmod u+r, u+w chmod u+rw,g+w, o+r
chmod u+x filenmame //只想给自己运行,别人只能读
chmod 777 (用数字的方式设置权限是最常用的)
数字表示权限时,各数位分别表示属主(user)、属组(group)及其他人(other);
其中,1是执行权(Execute),2是写权限(Write),4是读权限(Read),
具体权限相当于三种权限的数相加,如7=1+2+4,即拥有读写和执行权。
另外,临时文件/目录的权限为rwt,可写却不可删,关机后自动删除;建临时目录:chmod 777 目录名,再chmod +t 目录名。

id 显示用户有效的uid(用户字)和gid(组名)
用法 id [-ap] [user]
id 显示自己的。
id root 显示root的。
id -a root 显示用户所在组的所有组名(如root用户,是所有组的组员)
df 查看文件系统,查看数据区
用法 df [-F FSType] [-abeghklntVvZ] [-o FSType 特定选项] [目录 | 块设备 | 资源]
df -k 以kbytes显示文件大小的查看文件系统方式


六、显示文件内容
more 分屏显示文件的内容。
用法 more [-cdflrsuw] [-行] [+行号] [+/模式] [文件名 ...]。
显示7个信息:用户名 密码 用户id(uid) 组id(gid) 描述信息(一般为空) 用户主目录 login shell(登录shell)
cat 显示文件内容,不分屏(一般用在小文件,大文件显示不下);合并文件,仅在屏幕上合并,并不改变原文件。
用法 cat [ -usvtebn ] [-|文件] ...
如:cat>1.c //就可以把代码粘帖到1.c文件里,按ctrl+d 保存代码。
cat 1.c 或more 1.c //都可以查看里面的内容。
gcc -o 1 1.c //将1.c编译成.exe文件,我们可以用此命编译出代码。
tail 实时监控文件,一般用在日志文件,可以只看其中的几行。
用法 tail [+/-[n][lbc][f]] [文件]
tail [+/-[n][l][r|f]] [文件]


七、文件/目录的增删
echo 显示一行内容。
touch 如果文件/目录不存在,则创建新文件/目录;如果文件存在,那么就是更新该文件的最后访问时间,
用法 touch [-acm] [-r ref_file] 文件...
touch [-acm] [MMDDhhmm[yy]] 文件...
touch [-acm] [-t [[CC]YY]MMDDhhmm[.SS]] file...
mkdir 创建目录(必须有创建目录的权限)
用法 mkdir [-m 模式] [-p] dirname ...
mkdir dir1/dir2 在dir1下建dir2
mkdir dir13 dir4 dir5 连建多个
mkdir ~/games 用户主目录下建(默认在当前目录下创建)
mkdir -p dir6/dir7/dir8 强制创建dir8;若没有前面的目录,会自动创建dir6和dir7。
不用-p时,若没有dir6/dir7,则创建失败。

cp 复制文件/目录
cp 源文件 目标文件 复制文件;若已有文件则覆盖
cp -r 源目录 目标目录 复制目录;若已有目录则把源目录复制到目标目录下,
没有目标目录时,相当于完全复制源目录,只是文件名不同。
如:cp beans apple dir2 把beans、apple文件复制到dir2目录下
cp 1.c netseek/2.c 将1.c拷到netseek目录下并命名为2.c
cp -i beans apple 增加是否覆盖的提示

mv 移动或重命名文件/目录
用法 mv [-f] [-i] f1 f2
mv [-f] [-i] f1 ... fn d1
mv [-f] [-i] d1 d2
mv 源文件名 目标文件名 若目标文件名还没有,则是源文件重命名为目标文件;若目标文件已存在,则源文件覆盖目标文件。
mv 源文件名 目标目录 移动文件
mv 源目录 目标目录 若目标目录不存在,则源目录重命名;若目标目录已存在,则源目录移动到目标目录下。
如:mv qib.tgz ../qib.tgz 移到上一级目录

rm 删除文件/目录
用法 rm [-fiRr] 文件 ...
rm 文件名 删除文件。
rm -r 目录名 删除目录。
rm –f 文件 只要是该文件或者目录的拥有者,无论是否有权限删除,都可以用这个命令参数强行删除。
rm -rf * 删除所有文件及目录
rmdir 删除空目录。只可以删除空目录。

ln 创建硬链接或软链接,硬链接=同一文件的多个名字;软链接=快捷方式
用法 ln [-f] [-n] [-s] f1 [f2]
ln [-f] [-n] [-s] f1 ... fn d1
ln [-f] [-n] -s d1 d2
ln file1 file1.ln 创建硬链接。感觉是同一文件,删除一个,对另一个没有影响;须两个都删除才算删除。
ln -s file1 file1.sln 创建软链接。可跨系统操作,冲破操作权限;也是快捷方式。


八、时间显示
date 显示时间,精确到秒
用法 date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cal 显示日历
cal 9 2008 显示2008年9月的日历; cal 显示当月的
用法 cal [ [月] 年 ]

九、帮助
man 对某命令提供帮助解释
帮助( format and display the on-line manual pages)
用法 man [-] [-adFlrt] [-M 路径] [-T 宏软件包] [-s 段] 名称 ...
man [-] [-adFlrt] [-M path] [-T macro-package] [-s section] name...
man [-M 路径] -k 关键字 ...
man [-M 路径] -f 文件 ...
如: man ls 就可以查看ls相关的用法


awk 按一定格式输出(pattern scanning and processing language)
用法 awk [-Fc] [-f 源代码 | 'cmds'] [文件]


十、vi
底行模式 / ? 命令模式 i a o 输入模式

vi 的使用方法
1、光标 h 左 j 下 k 上 l 右
set nu 显示行号(set nonu) 21 光标停在指定行
21G 第N行 (G到文件尾,1G到文件头) 如果要将光标移动到文件第一行,那么就按 1G
H 屏幕头
M 屏幕中间
L 屏幕底
^ 或 shift+6 行首
$ 或 shift+4 行尾
Ctrl+f 下翻
Ctrl+b 上翻

2、输入 (输入模式)
o 光标往下换一行
O (大写字母o)在光标所在行上插入一空行
i 在光标所在位置的前面插入字母
a 在光标所在位置的后面插入一个新字母
<Esc> 退出插入状态。

3、修改替换
r 替换一个字符
dd 删除行,剪切行 (5dd删除5行)
5,10d 删除 5 至 10 行(包括第 5行和第 10 行)
x 删除一个字符
dw 删除词,剪切词。 ( 3dw删除 3 单词)
cw 替换一个单词。 (cw 和 dw 的区别 cw 删除某一个单词后直接进入编辑模式,而dw删除词后仍处于命令模式)
cc 替换一行
C 替换从光标到行尾
yy 复制行 (用法同下的 Y ,见下行)
Y 将光标移动到要复制行位置,按yy。当你想粘贴的时候,请将光标移动到你想复制的位置的前一个位置,然后按 p
yw 复制词
p 当前行下粘贴
1,2co3 复制行1,2在行3之后
4,5m6 移动行4,5在行6之后
u 当你的前一个命令操作是一个误操作的时候,那么可以按一下 u键,即可复原。只能撤销一次
r file2 在光标所在处插入另一个文件

~ 将字母变成大写
J 可以将当前行与下一行连接起来
/字符串 从上往下找匹配的字符串
?字符串 从下往上找匹配的字符串
n 继续查找
1,$s/旧串/新串/g 替换全文(或者 %s/旧串/新串/g)
(1表示从第一行开始) 没有g则只替换一次,加g替换所有

4、存盘和退出
w 存盘
w newfile 存成新文件
wq 存盘再退出VI(或者ZZ或 X)
q! 强行退出不存盘

查看用户
users 显示在线用户(仅显示用户名)。
who 显示在线用户,但比users更详细,包括用户名、终端号、登录时间、IP地址。
who am i 仅显示自己,(但包括用户名、端口、登录时间、IP地址;信息量=who)。
whoami 也仅显示自己,但只有用户名(仅显示自己的有效的用户名)。
w 显示比who更多内容,还包括闲置时间、占CPU、平均占用CPU、执行命令。
用法 w [ -hlsuw ] [ 用户 ]
whereis 查询命令所在目录以及帮助文档所在目录
如: whereis bin 显示bin所在的目录,将显示为:/usr/local/bin
which 查询该命令所在目录(类似whereis)

su 改变用户,需再输入密码。在不退出登陆的情况下,切换到另外一个人的身份
用法 su [-] [ username [ arg ... ] ]
su - 相当于退出再重新登录。
su -l 用户名(如果用户名缺省,则切换到root状态;将提示输入密码)

查找
find 查找文件(文件或者目录名以及权限属主等匹配搜索)
用法 find [-H | -L] 路径列表 谓词列表
find / -name perl 从根目录开始查找名为perl的文件。
find . -mtime 10 -print 从当前目录查找距离现在10天时修改的文件,显示在屏幕上。
(注 “10”表示第10天的时候;如果是“+10”表示10天以外的范围;“-10”表示10天以内的范围。)
finger 可以让使用者查询一些其他使用者的资料
如:finger 查看所用用户的使用资料
finger root 查看root的资料
grep 文件中查找字符;有过滤功能,只列出想要的内容
用法 grep -hblcnsviw 模式 文件 . . .
如 grep abc /etc/passwd 在passwd文件下找abc字符
grep success *    查找当前目录下面所有文件里面含有success字符的文件
wc 统计
-l 统计行数; -w统计单词数; -c 统计字符数
如 grep wang /etc/passwd|wc -l 统计passwd文件含“wang”的行数
du 查看目录情况
如 du -sk * 不加-s会显示子目录,-k按千字节排序
用法 du [-a] [-d] [-h|-k] [-r] [-o|-s] [-H|-L] [文件...]

进程管理
ps 显示进程。
用法 ps [ -aAdeflcjLPyZ ] [ -o 格式 ] [ -t 项列表 ]
[ -u 用户列表 ] [ -U 用户列表 ] [ -G 组列表 ]
[ -p 进程列表 ] [ -g 程序组列表 ] [ -s 标识符列表 ] [ -z 区域列表 ]
ps 显示自己的进程。
ps -e 显示每个进程,包括空闲进程。
ps -f 显示详情。
ps -ef 组合-e和-f,所有进程的详情。
ps -U uidlist(用户列表) 具体查看某人的进程。

kill 可以杀死某个正在进行或者已经是dest状态的进程
pkill
sleep

passwd 可以设置口令

history 用户用过的命令
如: history 可以显示用户过去使用的命令

jobs
用法 jobs [-l ]
fg %n
bg %n
stop %n 挂起(仅csh能用)
Ctrl+C
Ctrl+Z

网络链接
ping
usage ping host [timeout]
usage ping -s [-l | U] [adLnRrv] [-A addr_family] [-c traffic_class] [-g gateway [-g gateway ...]] [-F flow_label] [-I interval] [-i interface] [-P tos] [-p port] [-t ttl] host [data_size] [npackets]

ifconfig -a
/sbin/ifconfig 查看本机的IP地址

netstat -rn


rlogin

ftp


mount 加载一个硬件设备
用法:mount [参数] 要加载的设备 载入点
如: mount /dev/cdrom
cd /mnt/cdrom //进入光盘目录


tar 解压命令
tar -zxvf nmap-3.45.tgz 将这个解压到nmap-3.45这个目录里











帮助文件 [sd0807@localhost ~]$ help
GNU bash, version 3.1.17(1)-release (i686-redhat-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 [&] (( expression ))
. filename [arguments]
[ arg... ] [[ expression ]]
alias [-p] [name[=value] ... ] bg [job_spec ...]
bind [-lpvsPVS] [-m keymap] [-f fi break [n]
builtin [shell-builtin [arg ...]] caller [EXPR]
case WORD in [PATTERN [| PATTERN]. cd [-L|-P] [dir]
command [-pVv] command [arg ...] compgen [-abcdefgjksuv] [-o option
complete [-abcdefgjksuv] [-pr] [-o continue [n]
declare [-afFirtx] [-p] [name[=val dirs [-clpv] [+N] [-N]
disown [-h] [-ar] [jobspec ...] echo [-neE] [arg ...]
enable [-pnds] [-a] [-f filename] eval [arg ...]
exec [-cl] [-a name] file [redirec exit [n]
export [-nf] [name[=value] ...] or false
fc [-e ename] [-nlr] [first] [last fg [job_spec]
for NAME [in WORDS ... ;] do COMMA for (( exp1; exp2; exp3 )); do COM
function NAME { COMMANDS ; } or NA getopts optstring name [arg]
hash [-lr] [-p pathname] [-dt] [na help [-s] [pattern ...]
history [-c] [-d offset] [n] or hi if COMMANDS; then COMMANDS; [ elif
jobs [-lnprs] [jobspec ...] or job kill [-s sigspec | -n signum | -si
let arg [arg ...] local name[=value] ...
logout popd [+N | -N] [-n]
printf [-v var] format [arguments] pushd [dir | +N | -N] [-n]
pwd [-LP] read [-ers] [-u fd] [-t timeout] [
readonly [-af] [name[=value] ...] return [n]
select NAME [in WORDS ... ;] do CO set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
shift [n] shopt [-pqsu] [-o long-option] opt
source filename [arguments] suspend [-f]
test [expr] time [-p] PIPELINE
times trap [-lp] [arg signal_spec ...]
true type [-afptP] name [name ...]
typeset [-afFirtx] [-p] name[=valu ulimit [-SHacdfilmnpqstuvx] [limit
umask [-p] [-S] [mode] unalias [-a] name [name ...]
unset [-f] [-v] [name ...] until COMMANDS; do COMMANDS; done
variables - Some variable names an wait [n]
while COMMANDS; do COMMANDS; done { COMMANDS ; }



输入 man help

BASH_BUILTINS(1) BASH_BUILTINS(1)

NAME
bash, :, ., [, alias, bg, bind, break, builtin, cd, command, compgen, complete, continue,
declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help,
history, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return,
set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, una-
lias, unset, wait - bash built-in commands, see bash(1)

BASH BUILTIN COMMANDS
Unless otherwise noted, each builtin command documented in this section as accepting options
preceded by - accepts -- to signify the end of the options. For example, the :, true,
false, and test builtins do not accept options.
: [arguments]
No effect; the command does nothing beyond expanding arguments and performing any
specified redirections. A zero exit code is returned.

. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell environment and return
the exit status of the last command executed from filename. If filename does not
contain a slash, file names in PATH are used to find the directory containing file-
name. The file searched for in PATH need not be executable. When bash is not in
posix mode, the current directory is searched if no file is found in PATH. If the
sourcepath option to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the positional parameters when
filename is executed. Otherwise the positional parameters are unchanged. The return
status is the status of the last command exited within the script (0 if no commands
are executed), and false if filename is not found or cannot be read.

alias [-p] [name[=value] ...]
Alias with no arguments or with the -p option prints the list of aliases in the form
alias name=value on standard output. When arguments are supplied, 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. For each
name in the argument list for which no value is supplied, the name and value of the
alias is printed. Alias returns true unless a name is given for which no alias has
been defined.

bg [jobspec ...]
Resume each suspended job jobspec in the background, as if it had been started with
&. If jobspec is not present, the shell’s notion of the current job is used. bg
jobspec returns 0 unless run when job control is disabled or, when run with job con-
trol enabled, any specified jobspec was not found or was started without job control.

bind [-m keymap] [-lpsvPSV]
bind [-m keymap] [-q function] [-u function] [-r keyseq]
bind [-m keymap] -f filename
bind [-m keymap] -x keyseq:shell-command
bind [-m keymap] keyseq:function-name
bind readline-command
Display current readline key and function bindings, bind a key sequence to a readline
function or macro, or set a readline variable. Each non-option argument is a command
as it would appear in .inputrc, but each binding or command must be passed as a sepa-
rate argument; e.g., ’"\C-x\C-r": re-read-init-file’. Options, if supplied, have the
following meanings:
-m keymap
Use keymap as the keymap to be affected by the subsequent bindings. Accept-
able keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi,
vi-move, vi-command, and vi-insert. vi is equivalent to vi-command; emacs is
equivalent to emacs-standard.
-l List the names of all readline functions.
-p Display readline function names and bindings in such a way that they can be
re-read.
-P List current readline function names and bindings.
-v Display readline variable names and values in such a way that they can be re-
read.
-V List current readline variable names and values.
-s Display readline key sequences bound to macros and the strings they output in
such a way that they can be re-read.
-S Display readline key sequences bound to macros and the strings they output.
-f filename
Read key bindings from filename.
-q function
Query about which keys invoke the named function.
-u function
Unbind all keys bound to the named function.
-r keyseq
Remove any current binding for keyseq.
-x keyseq:shell-command
Cause shell-command to be executed whenever keyseq is entered.

The return value is 0 unless an unrecognized option is given or an error occurred.

break [n]
Exit from within a for, while, until, or select loop. If n is specified, break n
levels. n must be ≥ 1. If n is greater than the number of enclosing loops, all
enclosing loops are exited. The return value is 0 unless the shell is not executing
a loop when break is executed.

builtin shell-builtin [arguments]
Execute the specified shell builtin, passing it arguments, and return its exit sta-
tus. This is useful when defining a function whose name is the same as a shell
builtin, retaining the functionality of the builtin within the function. The cd
builtin is commonly redefined this way. The return status is false if shell-builtin
is not a shell builtin command.

cd [-L|-P] [dir]
Change the current directory to dir. The variable HOME is the default dir. The
variable CDPATH defines the search path for the directory containing dir. Alterna-
tive directory names in CDPATH are separated by a colon (:). A null directory name
in CDPATH is the same as the current directory, i.e., ‘‘.’’. If dir begins with a
slash (/), then CDPATH is not used. The -P option says to use the physical directory
structure instead of following symbolic links (see also the -P option to the set
builtin command); the -L option forces symbolic links to be followed. An argument of
- is equivalent to $OLDPWD. If a non-empty directory name from CDPATH is used, or if
- is the first argument, and the directory change is successful, the absolute path-
name of the new working directory is written to the standard output. The return
value is true if the directory was successfully changed; false otherwise.

caller [expr]
Returns the context of any active subroutine call (a shell function or a script exe-
cuted with the . or source builtins. Without expr, caller displays the line number
and source filename of the current subroutine call. If a non-negative integer is
supplied as expr, caller displays the line number, subroutine name, and source file
corresponding to that position in the current execution call stack. This extra
information may be used, for example, to print a stack trace. The current frame is
frame 0. The return value is 0 unless the shell is not executing a subroutine call
or expr does not correspond to a valid position in the call stack.

command [-pVv] command [arg ...]
Run command with args suppressing the normal shell function lookup. Only builtin com-
mands or commands found in the PATH are executed. If the -p option is given, the
search for command is performed using a default value for PATH that is guaranteed to
find all of the standard utilities. If either the -V or -v option is supplied, a
description of command is printed. The -v option causes a single word indicating the
command or file name used to invoke command to be displayed; the -V option produces a
more verbose description. If the -V or -v option is supplied, the exit status is 0
if command was found, and 1 if not. If neither option is supplied and an error
occurred or command cannot be found, the exit status is 127. Otherwise, the exit
status of the command builtin is the exit status of command.

compgen [option] [word]
Generate possible completion matches for word according to the options, which may be
any option accepted by the complete builtin with the exception of -p and -r, and
write the matches to the standard output. When using the -F or -C options, the vari-
ous shell variables set by the programmable completion facilities, while available,
will not have useful values.

The matches will be generated in the same way as if the programmable completion code
had generated them directly from a completion specification with the same flags. If
word is specified, only those completions matching word will be displayed.

The return value is true unless an invalid option is supplied, or no matches were
generated.

complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G globpat] [-W wordlist] [-P prefix]
[-S suffix]
[-X filterpat] [-F function] [-C command] name [name ...]
complete -pr [name ...]
Specify how arguments to each name should be completed. If the -p option is sup-
plied, or if no options are supplied, existing completion specifications are printed
in a way that allows them to be reused as input. The -r option removes a completion
specification for each name, or, if no names are supplied, all completion specifica-
tions.

The process of applying these completion specifications when word completion is
attempted is described above under Programmable Completion.

Other options, if specified, have the following meanings. The arguments to the -G,
-W, and -X options (and, if necessary, the -P and -S options) should be quoted to
protect them from expansion before the complete builtin is invoked.
-o comp-option
The comp-option controls several aspects of the compspec’s behavior beyond
the simple generation of completions. comp-option may be one of:
bashdefault
Perform the rest of the default bash completions if the compspec gen-
erates no matches.
default Use readline’s default filename completion if the compspec generates
no matches.
dirnames
Perform directory name completion if the compspec generates no
matches.
filenames
Tell readline that the compspec generates filenames, so it can per-
form any filename-specific processing (like adding a slash to direc-
tory names or suppressing trailing spaces). Intended to be used with
shell functions.
nospace Tell readline not to append a space (the default) to words completed
at the end of the line.
plusdirs
After any matches defined by the compspec are generated, directory
name completion is attempted and any matches are added to the results
of the other actions.
-A action
The action may be one of the following to generate a list of possible comple-
tions:
alias Alias names. May also be specified as -a.
arrayvar
Array variable names.
binding Readline key binding names.
builtin Names of shell builtin commands. May also be specified as -b.
command Command names. May also be specified as -c.
directory
Directory names. May also be specified as -d.
disabled
Names of disabled shell builtins.
enabled Names of enabled shell builtins.
export Names of exported shell variables. May also be specified as -e.
file File names. May also be specified as -f.
function
Names of shell functions.
group Group names. May also be specified as -g.
helptopic
Help topics as accepted by the help builtin.
hostname
Hostnames, as taken from the file specified by the HOSTFILE shell
variable.
job Job names, if job control is active. May also be specified as -j.
keyword Shell reserved words. May also be specified as -k.
running Names of running jobs, if job control is active.
service Service names. May also be specified as -s.
setopt Valid arguments for the -o option to the set builtin.
shopt Shell option names as accepted by the shopt builtin.
signal Signal names.
stopped Names of stopped jobs, if job control is active.
user User names. May also be specified as -u.
variable
Names of all shell variables. May also be specified as -v.
-G globpat
The filename expansion pattern globpat is expanded to generate the possible
completions.
-W wordlist
The wordlist is split using the characters in the IFS special variable as
delimiters, and each resultant word is expanded. The possible completions
are the members of the resultant list which match the word being completed.
-C command
command is executed in a subshell environment, and its output is used as the
possible completions.
-F function
The shell function function is executed in the current shell environment.
When it finishes, the possible completions are retrieved from the value of
the COMPREPLY array variable.
-X filterpat
filterpat is a pattern as used for filename expansion. It is applied to the
list of possible completions generated by the preceding options and argu-
ments, and each completion matching filterpat is removed from the list. A
leading ! in filterpat negates the pattern; in this case, any completion not
matching filterpat is removed.
-P prefix
prefix is added at the beginning of each possible completion after all other
options have been applied.
-S suffix
suffix is appended to each possible completion after all other options have
been applied.

The return value is true unless an invalid option is supplied, an option other than
-p or -r is supplied without a name argument, an attempt is made to remove a comple-
tion specification for a name for which no specification exists, or an error occurs
adding a completion specification.

continue [n]
Resume the next iteration of the enclosing for, while, until, or select loop. If n
is specified, resume at the nth enclosing loop. n must be ≥ 1. If n is greater than
the number of enclosing loops, the last enclosing loop (the ‘‘top-level’’ loop) is
resumed. The return value is 0 unless the shell is not executing a loop when con-
tinue is executed.

declare [-afFirtx] [-p] [name[=value] ...]
typeset [-afFirtx] [-p] [name[=value] ...]
Declare variables and/or give them attributes. If no names are given then display
the values of variables. The -p option will display the attributes and values of
each name. When -p is used, additional options are ignored. The -F option inhibits
the display of function definitions; only the function name and attributes are
printed. If the extdebug shell option is enabled using shopt, the source file name
and line number where the function is defined are displayed as well. The -F option
implies -f. The following options can be used to restrict output to variables with
the specified attribute or to give variables attributes:
-a Each name is an array variable (see Arrays above).
-f Use function names only.
-i The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC
EVALUATION ) is performed when the variable is assigned a value.
-r Make names readonly. These names cannot then be assigned values by subsequent
assignment statements or unset.
-t Give each name the trace attribute. Traced functions inherit the DEBUG and
RETURN traps from the calling shell. The trace attribute has no special mean-
ing for variables.
-x Mark names for export to subsequent commands via the environment.

Using ‘+’ instead of ‘-’ turns off the attribute instead, with the exception that +a
may not be used to destroy an array variable. When used in a function, makes each
name local, as with the local command. If a variable name is followed by =value, the
value of the variable is set to value. The return value is 0 unless an invalid
option is encountered, an attempt is made to define a function using ‘‘-f foo=bar’’,
an attempt is made to assign a value to a readonly variable, an attempt is made to
assign a value to an array variable without using the compound assignment syntax (see
Arrays above), one of the names is not a valid shell variable name, an attempt is
made to turn off readonly status for a readonly variable, an attempt is made to turn
off array status for an array variable, or an attempt is made to display a non-exis-
tent function with -f.

dirs [-clpv] [+n] [-n]
Without options, displays the list of currently remembered directories. The default
display is on a single line with directory names separated by spaces. Directories
are added to the list with the pushd command; the popd command removes entries from
the list.
+n Displays the nth entry counting from the left of the list shown by dirs when
invoked without options, starting with zero.
-n Displays the nth entry counting from the right of the list shown by dirs when
invoked without options, starting with zero.
-c Clears the directory stack by deleting all of the entries.
-l Produces a longer listing; the default listing format uses a tilde to denote
the home directory.
-p Print the directory stack with one entry per line.
-v Print the directory stack with one entry per line, prefixing each entry with
its index in the stack.

The return value is 0 unless an invalid option is supplied or n indexes beyond the
end of the directory stack.

disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of active jobs. If the -h
option is given, each jobspec is not removed from the table, but is marked so that
SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is
present, and neither the -a nor the -r option is supplied, the current job is used.
If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r
option without a jobspec argument restricts operation to running jobs. The return
value is 0 unless a jobspec does not specify a valid job.

echo [-neE] [arg ...]
Output the args, separated by spaces, followed by a newline. The return status is
always 0. If -n is specified, the trailing newline is suppressed. If the -e option
is given, interpretation of the following backslash-escaped characters is enabled.
The -E option disables the interpretation of these escape characters, even on systems
where they are interpreted by default. The xpg_echo shell option may be used to
dynamically determine whether or not echo expands these escape characters by default.
echo does not interpret -- to mean the end of options. echo interprets the following
escape sequences:
\a alert (bell)
\b backspace
\c suppress trailing newline
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\0nnn the eight-bit character whose value is the octal value nnn (zero to three
octal digits)
\nnn the eight-bit character whose value is the octal value nnn (one to three octal
digits)
\xHH the eight-bit character whose value is the hexadecimal value HH (one or two
hex digits)

enable [-adnps] [-f filename] [name ...]
Enable and disable builtin shell commands. Disabling a builtin allows a disk command
which has the same name as a shell builtin to be executed without specifying a full
pathname, even though the shell normally searches for builtins before disk commands.
If -n is used, each name is disabled; otherwise, names are enabled. For example, to
use the test binary found via the PATH instead of the shell builtin version, run
‘‘enable -n test’’. The -f option means to load the new builtin command name from
shared object filename, on systems that support dynamic loading. The -d option will
delete a builtin previously loaded with -f. If no name arguments are given, or if
the -p option is supplied, a list of shell builtins is printed. With no other option
arguments, the list consists of all enabled shell builtins. If -n is supplied, only
disabled builtins are printed. If -a is supplied, the list printed includes all
builtins