Linux基础-01 Linux Bash初识

01 Linux Bash初识

Bash Shell介绍

什么是Bash? 什么是 Shell ?

Bash是Shell的一种, 而Shell是一个命令解释器,它在操作系统的最外层,负责用户程序与内核进行交互操作的一种接口,讲用户输入的命令翻译给操作系统,并将处理后的结果输出至屏幕。


Bash Shell的作用

使用Shell实现对Linux系统的大部分管理,例如:
1)文件管理
2)权限管理
3)用户管理
4)磁盘管理
5)网络管理
6)软件管理
7)应用管理
...等等管理


使用命令查看bash版本

[root@db04 ~]# bash -version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

命令提示符

# 命令提示符介绍
[root@localhost ~]#
root:当前登录的⽤户
@:分隔符
localhost:当前的主机名
~:当前登录⽤户的家⽬录
#:默认#代表,当前⽤户是超级⽤户
$:默认代表普通⽤户

# 查看当前登陆用户
[root@localhost ~]# whoami
root

# 查看当前命令提示符
[root@localhost ~]# echo $PS1
[\u@\h \W]\$

# 修改root环境变量下命令提示符
[root@localhost ~]# cat >> /etc/profile << EOF
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\[\e[35;40m\]\h\[\e[0m\] \[\e[36;40m\]\w\[\e[0m\]]\\$ "
EOF
[root@localhost ~]# source /etc/profile

Bash Shell基础语法

# 语法
command [option...] [argument...]
命令     选项         参数

# 注意
1.选项可以多个
ls -lah /etc/passwd

2.参数可以多个
ls /etc/passwd /tmp

Bash Shell的基本特性

命令补全

  • 补全命令: tab键

  • 补全选项

    • ⻓格式: 默认长格式不支持, 需要安装第三方包yum install -y bash-completion
    • 短格式: 短格式没有补全一说
  • 补全参数: tab键

PS: 补全操作两下tab键支持命令展示

[root@~ 05:50:54]# ifc
ifcfg     ifconfig

命令快捷键

# 常用命令
Ctrl + a        # 将光标移动到⾏⾸
Ctrl + e        # 将光标移动到⾏末
Ctrl + w        # 以空格为分隔符删除光标之前的内容
Ctrl + u        # 删除光标之前的所有内容
Ctrl + c        # 终⽌⼀个正在运⾏的命令
Ctrl + d        # 注销 相当于命令:exit 或者 logout 
Ctrl + z        # 将在前台运⾏的程序放到后台
Ctrl + l        # 清屏 相当于命令:clear 
Ctrl + r        # 搜索历史命令
ESC	+ .         # 以空格为分隔符,打印出上⼀条命令最后⼀个空格后的内容
Ctrl + 左右      # 按照单词快速跳转光标(Xshell提供的)

# 不常用命令
Ctrl + s        # 锁屏
Ctrl + q        # 解锁

历史命令

专业名词:审计

# 参数介绍
-w		# 保存命令历史到文件 write
-c		# 清空命令历史记录,不会清空文件 clear
-d		# 删除命令历史的第N行 delete

# 查看历史记录
[root@localhost ~]# history

# 清空历史记录
[root@localhost ~]# history -c

# 指定一条历史记录删除
[root@localhost ~]# history -d 110

# 保存历史命令
[root@localhost ~]# history -w

# 执行上一条命令
[root@localhost ~]# !!

# 执行上一条ls相关命令
[root@localhost ~]# !ls
ls /etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0

# 执行历史命令中的第74条命令
[root@localhost ~]# !74

命令的别名

命令别名讲用户经常使用的复杂命令简单化,创建出属于自己的命令别名。

# 查看别名
[root@localhost ~]# alias 

# 临时取消别名
[root@localhost ~]# unalias ll
[root@localhost ~]# ll
-bash: ll: command not found

# 临时设置别名
[user1@localhost ~]$ alias ckwl='ifconfig'

# 当前登陆用户永久修改别名
[root@localhost ~]# vim /root/.bashrc
alias ggg='cat /etc/passwd'
[root@localhost ~]# source /root/.bashrc

# 永久修改别名
[root@localhost ~]# vim /etc/bashrc
alias xxx='cat /etc/passwd' 
[root@localhost ~]# xxx
-bash: xxx: command not found
[root@localhost ~]# source /etc/bashrc

# 通过设置别名方式控制rm命令, 防止误删除
[user1@localhost ~]$ alias rm='echo "不允许执行rm命令"'
[user1@localhost ~]$ rm /tmp/a.txt 
不允许执行rm命令 /tmp/a.txt

获取命令帮助

Linux命令帮助中文参考网址

# man
[root@localhost ~]# man ls

# --help
[root@localhost ~]# ls --help

命令执行的流程

pass

posted @ 2021-07-08 09:28  给你加马桶唱疏通  阅读(82)  评论(0编辑  收藏  举报