Bash的特性
Bash特性
目录- Bash特性
- 基础语法
- 命令补全
- Bash快捷键
- 历史命令
- 命令的别名
- Linux系统中帮助文档
- 思维导图
基础语法
命令 [选项] [参数]
command [option] [argument]
# (路径 文件等)
# (在语法中,中括号是可有可无的意思)
list
ls 查看当前所在工作目录下的文件和目录
-a:查看所有文件包括隐藏文件
root@localhost:~\ # ls -a
. .. anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .cshrc .tcshrc
-l: 查看所有文件的详细信息
root@localhost:~\ # ls -l
total 4
-rw-------. 1 root root 1447 Mar 15 18:32 anaconda-ks.cfg
-la: 查看所有隐藏文件且包含隐藏文件的详细信息
root@localhost:~\ # ls -la
total 28
dr-xr-x---. 2 root root 135 Mar 17 11:17 .
dr-xr-xr-x. 17 root root 224 Mar 15 18:30 ..
-rw-------. 1 root root 1447 Mar 15 18:32 anaconda-ks.cfg
-rw-------. 1 root root 359 Mar 17 11:05 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 232 Mar 17 11:17 .bashrc
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
命令补全
# Tab键
# 默认可以补全,命令和参数
Bash快捷键
Ctrl + l:清屏
Ctrl + c:终止命令的执行
Ctrl + e:end 将光标快速移动到行末
Ctrl + a:ahead 将光标快速移动到行首
Ctrl + w:以空格为分隔符,删除光标前面到空格之间的内容
Ctrl + k:删除光标之后的所有内容
Ctrl + u:删除光标之前的所有内容
Ctrl + d:退出当前用户的登录
Ctrl + r:搜索执行过的历史命令
Ctrl + 左右:按照单词移动光标
ESC + . :复制上一条命令,最后一个空格后面的内容
---------------------------------------------------------
(#+内容) 注释:是给人看的,计算机不认识,可以自己加注备注来解释内容
举例:
alias net='vi /etc/sysconfig/network-scripts/ifcfg-ens33'
root@localhost:~\ # #net=修改网卡
历史命令
history
-c:clear 清除历史命令
-d:delete 删除指定编号的历史命令
-w:write 保存历史命令到一个文件中(将历史命令保存到家目录下的.bash_history 隐藏文件中)
-----------------------------------------------
!+命令的一部分:执行history中上一条,含有该命令一部分的命令内容 (常用)
!!:执行上一条命令
!+数字:执行历史命令中编号所在命令内容
# 举例
history
# -c:clear 清除历史命令
[root@localhost [~]# history
1 history
2 ls -a
3 ls -l
4 history
5 vi .bashrc
6 source .bashrc
7 history
8 history -d 4
9 history
[root@localhost [~]# history -c
[root@localhost [~]# history
1 history
[root@localhost [~]#
# -d:delete 删除指定编号的历史命令
[root@localhost [~]# history
1 history
2 ls -a
3 ls -l
4 ls -la
5 history
6 vi .bashrc
7 source .bashrc
8 history
[root@localhost [~]# history -d 4
[root@localhost [~]# history
1 history
2 ls -a
3 ls -l
4 history
5 vi .bashrc
6 source .bashrc
7 history
8 history -d 4
9 history
# -w:write 保存历史命令到一个文件中(将历史命令保存到家目录下的.bash_history 隐藏文件中)
[~]# history -w
[root@localhost [~]# ls .bash
.bash_history .bash_logout .bash_profile .bashrc
[root@localhost [~]# ls .bash_history
!+命令的一部分:执行上一条,含有该命令一部分的命令内容 (常用)
- 上述命令vi 命令最后一次执行的是 vi .bashrc 即 !vi=vi .bashrc
root@localhost [~]# history
1 history
2 history -w
3 ls .bash
4 history
5 ls -a
6 ls *l-
7 ls -la
8 ping
9 history
10 vi /etc/sysconfig/network-scripts/ifcfg-ens33
11 ls
12 ls -a
13 vi /etc/sysconfig/network-scripts/ifcfg-ens33
14 vi
15 is
16 ls
17 vi /etc/sysconfig/network-scripts/ifcfg--ens33
18 ls -a
19 ls -la
20 vi
21 vi .bashrc
22 history
[root@localhost [~]# !vi
vi .bashrc
!!:执行上一条命令
- 上一条执行的命令是 !vi=vi .bashrc 即:!!这里也会执行vi .bashrc
[root@localhost [~]# history
1 history
2 history -w
3 ls .bash
4 history
5 ls -a
6 ls *l-
7 ls -la
8 ping
9 history
10 vi /etc/sysconfig/network-scripts/ifcfg-ens33
11 ls
12 ls -a
13 vi /etc/sysconfig/network-scripts/ifcfg-ens33
14 vi
15 is
16 ls
17 vi /etc/sysconfig/network-scripts/ifcfg--ens33
18 ls -a
19 ls -la
20 vi
21 vi .bashrc
22 history
[root@localhost [~]# !vi
vi .bashrc
[root@localhost [~]# !!
vi .bashrc
!+数字:执行历史命令中编号所在命令内容
- 历史里第28执行了 ls -a 即 !28=ls -a
[root@localhost [~]# history
1 history
2 history -w
3 ls .bash
4 history
5 ls -a
6 ls *l-
7 ls -la
8 ping
9 history
10 vi /etc/sysconfig/network-scripts/ifcfg-ens33
11 ls
12 ls -a
13 vi /etc/sysconfig/network-scripts/ifcfg-ens33
14 vi
15 is
16 ls
17 vi /etc/sysconfig/network-scripts/ifcfg--ens33
18 ls -a
19 ls -la
20 vi
21 vi .bashrc
22 history
23 vi .bashrc
24 history
25 ls -a
26 ls-la
27 ls -la
28 ls -a
29 !!
30 history
[root@localhost [~]# !28
ls -a
. .. anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .cshrc .tcshrc
命令的别名
# 查看系统内置的别名都有哪些
alias
# 设置别名
alias 别名="完整的命令"
设置别名后是临时生效
永久生效需要在 .bashrc 中编辑加上这个设置别名的完整命令
# 取消别名
unalias net
(别名)
举例:
1.查看系统内置的别名
alias
[root@localhost [~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grepa--color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
2.设置别名
? alias 别名="完整的命令"
? alias net='vi /etc/sysconsysconfig/network-scripts/ifcfg-ens33'
[root@localhost [~]# alias net='vi /etc/sysconsysconfig/network-scripts/ifcfg-ens33'
[root@localhost [~]# net
[root@localhost [~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias net='vi /etc/sysconsysconfig/network-scripts/ifcfg-ens33'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
alias wk='vi /etc/sysconsysconfig/network-scripts/ifcfg-ens33'
3.取消别名
unalias net
[root@localhost [~]# unalias net
[root@localhost [~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
Linux系统中帮助文档
man 命令
命令 --help
# 举例:
[root@localhost [~]# man ls
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
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
- Linux_命令手册中文介绍
linux命令在线中文手册 (51yip.com)