shell的概念_BASH特性
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]#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!