冲冲冲!DevOps·Linux篇·第二课时·Bash shell的初步认识
一、什么是Bash shell
Bash shell 是一个命令解释器,主要负责用户程序与内核进行交互操作的一种接口,将用户输入的命令翻译后传递给内核,内核驱动硬件去处理,最终输出结果到Bash shell控制台。
三、shell的基本使用
- 基本语法:
命令 | 选项 | 参数 |
---|---|---|
command | options | parameters |
命令:整条shell命令的主体功能
选项:以 - 短格式选项(单个字节),-a ; 以 – 长格式选项(多个字节),–all
参数:命令的操作对象,文件、目录
实例:
[root@zpedu01 /opt/shell]#ls
123 2021-04-21 2021-04-23 2021-04-25 test write.txt
[root@zpedu01 /opt/shell]#ls -a
. .. 123 2021-04-21 2021-04-23 2021-04-25 test write.txt
[root@zpedu01 /opt/shell]#ls -lh
total 164K
drwxr-xr-x. 2 root root 70 Apr 25 18:11 123
drwxr-xr-x. 2 root root 42 Apr 21 10:04 2021-04-21
drwxr-xr-x. 12 root root 139 Apr 25 11:58 2021-04-23
drwxr-xr-x. 2 root root 24 Apr 25 20:29 2021-04-25
drwxrwx---. 2 root root 19 Apr 26 17:20 test
-rw-r--r--. 1 root root 161K Apr 27 09:37 write.txt
- tabs命令补全功能
实例:
[root@zpedu01 /opt/shell]#ipta
#此时敲一下键盘的tabs,结果如下
[root@zpedu01 /opt/shell]#iptables
- alias别名的使用
临时定义别名:
#定义
[root@zpedu01 ~]#alias yy='yum install -y'
[root@zpedu01 ~]#yy vim
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Package 2:vim-enhanced-7.4.629-8.el7_9.x86_64 already installed and latest version
nothing to do
临时取消别名:
[root@zpedu01 ~]#unalias yy
别名永久生效:
[root@zpedu01 ~]#echo "alias yy='yum install -y'" >> /etc/bashrc
[root@zpedu01 ~]#source /etc/bashrc