shell的概念_BASH特性

发布时间 2023-10-09 17:35:51作者: WeChat2834
BASH特性
  • bash是一个命令处理器,运行在文本窗口中,并能执行用户直接输入的命令
  • bash还能从文件中读取Linux命令,称为脚本
  • bash支持通配符,管道,命令替换,条件判断等逻辑控制语句

bash有诸多方便的功能,有助于运维人员提升工作效率

命令历史

shelll会保留其会话中用户提交执行的命令

[root@localhost myshell]# echo $HISTSIZE
1000
###存放用户的历史执行命令,写入文件
[root@localhost myshell]# echo $HISTFILE
/root/.bash_history
[root@localhost myshell]# cat -n /root/.bash_history
......
   992	init 6
   993	pwd
   994	cd tmp
   995	ls -lah
   996	cat myshell.sh
   997	vim  myshell.sh
   998	init0
   999	init 0
  1000	shutdown
  [root@localhost myshell]#
  [root@localhost myshell]#
  ##清理历史命令,但是文件.bash_history中的命令还在
  [root@localhost myshell]# history  -c
  ##恢复历史命令
  [root@localhost myshell]# history  -r
  [root@localhost myshell]# 
  ##快速执行历史命令
  ....
 1009  ls -lah
 1010  cat myshell.sh
 1011  vim  myshell.sh
 1012  init0
 1013  init 0
 1014  shutdown
 1015  history 
[root@localhost myshell]# !1009
ls -lah
总用量 4.0K
drwxrwxr-x. 2 mrxu mrxu 27 8月  31 09:42 .
drwxrwxr-x. 3 mrxu mrxu 21 8月  31 09:40 ..
-rwxr--r--. 1 mrxu mrxu 50 8月  31 09:42 HelloShell.sh
[root@localhost myshell]# 
###!!快速执行上次命令
[root@localhost myshell]# !!,以及上下左右寻找
ls -lah
总用量 4.0K
drwxrwxr-x. 2 mrxu mrxu 27 8月  31 09:42 .
drwxrwxr-x. 3 mrxu mrxu 21 8月  31 09:40 ..
-rwxr--r--. 1 mrxu mrxu 50 8月  31 09:42 HelloShell.sh
[root@localhost myshell]# 

bash特性汇总
  • 文件路径tab键补全
  • 命令补全
  • 快捷键Ctrl+a,e,u,k,l
  • 通配符
  • 命令历史
  • 命令别名
  • 命令行展开
##输入ls -lah /etc/ 后按两下tab键
[root@localhost ~]# ls -lah /etc/
Display all 293 possibilities? (y or n)
###输入so后按TAB
[root@localhost ~]# so
soelim        sort          sosreport     sotruss       sound_dump    soundstretch  source        sox           soxi
###Ctrl +l快速清屏
bash多命令执行
[root@localhost tmp]# cd 
[root@localhost ~]# cd /home; cd tmp; ls -lah
总用量 84K
drwxr-xr-x.  4 root root 4.0K 8月  31 16:06 .
drwxr-xr-x. 17 root root 4.0K 8月  24 15:18 ..
-rw-r--r--.  1 root root   99 8月  23 17:25 !
-rw-r--r--.  1 root root    0 8月  24 16:52 0
-rw-r--r--.  1 root root    0 8月  24 15:57 0]
-rw-r--r--.  1 root root    0 8月  24 14:53 1
-rwxr-xr-x.  1 root root  135 8月  23 15:24 Demo01.sh
-rwxr--r--.  1 root root   57 8月  23 15:21 Demo02.sh
-rwxr--r--.  1 root root   90 8月  23 15:53 Demo03.sh
-rwxr--r--.  1 root root  260 8月  24 16:52 DemoFun.sh
-rwx--x-wx.  1 root root   27 8月  18 15:13 Hellwordmyshell
-rwxr-xr-x.  1 root root  215 8月  23 11:19 Mychoice2.sh
-rwxr-xr-x.  1 root root  193 8月  23 10:19 Mychoice.sh
drwxr-xr-x.  2 root root   39 8月  31 16:19 myshell
-rw-r--r--.  1 root root  235 8月  18 16:29 Myshelleg1.sh
-rw-r--r--.  1 root root   45 8月  18 17:06 Myshelleg2.sh
-rw-r--r--.  1 root root  146 8月  22 17:47 Mysum.sh
-rwxr-xr-x.  1 root root   83 8月  22 16:01 positionPara.sh
-rw-r--r--.  1 root root  144 8月  22 16:38 prPara.sh
drwxr-xr-x.  2 root root  111 8月  25 17:46 sqldb
-rwxr--r--.  1 root root  101 8月  23 17:43 TestFor2.sh
-rwxr--r--.  1 root root  154 8月  23 17:06 TestFor.sh
-rwxr-xr-x.  1 root root  123 8月  24 15:36 TestFun.sh
-rwxr--r--.  1 root root  193 8月  24 14:53 TestRead.sh
-rwxr-xr-x.  1 root root  152 8月  24 11:01 TestWhile.sh
[root@localhost tmp]#