bash shell 简介

bash shell 介绍

bash shell 是GNU 开发的一种命令解释器

bash shell 能做什么

  • 文件管理
  • 用户管理
  • 磁盘管理
  • 目录管理
  • 权限管理
  • 网络管理
  • 服务管理
  • 等等等等

执行方式

  • 命令执行 处理简单事物
  • 脚本执行 script 处理复杂事物

命令行介绍

[root@Zhang-linux ~]# 
[test@Zhang-linux ~]$
  • root 表示当前用户是超级管理员, root 的位置是当前用户
  • @ 分隔符
  • Zhang-linux 表示当前主机名
  • ~ 表示当前用户的家目录, 位置表示当前所在目录位置
  • 表示超级管理员提示符

  • $ 表示普通用户提示符

命令行结构

[root@qls ~]# ls -l   /root		#命令+选项+参数
total 4 -rw-------. 1 root root 1271 Oct 23 12:20 anaconda-ks.cfg 
  • 命令
  • [选项]
  • [参数/路径]

中括号中的 可以省略

命令的报错信息

  • command not found 找不到命令

    • 没有此命令, 或者 此系统没有安装此命令
    • 解决, 检查是否输入错误, 安装命令
  • No such file or directory 没有这个文件或目录

    • 没有此文件
    • 没有此目录
    • 文件所在目录错误
    • 解决, 检查目录或者文件路径
  • 选项

    • 短横杠 - 指定单一的功能,多个短横杠,可以写成 -abc -a -b -c
    • 长横岗 -- 一个完整字符串 例如 --all --help

bash 特性

tab 补全

  • 在输入命令首部几个字母时,按tab键 可以自动补全目录,
  • 按一次tab 没有反应时 ,有以下两种情况
    • 没有此命令
    • 有以此首部几个字母开头的命令有多个, 再次按tab键会显示所有以此开头的命令.

选项补全

		[root@qls ~]# yum  install  -y  bash-completion bash-completion-extra
		[root@qls ~]# systemctl   res
		rescue        reset-failed  restart

系统默认不支持,需要安装软件

参数补全

可以自动补全路径.

命令别名

[root@qls ~]# 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' 

自定义别名

利用alias命令可以自定义别名

[root@qls ~]# alias wang='ping baidu.com'
[root@qls ~]# wang
PING baidu.com (39.156.69.79) 56(84) bytes of data. 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=128 time=30.0 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=128 time=28.0 ms 

别名和 环境变量配置

个人

[root@qls ~]# ll  -a  .bash*
-rw-r--r--. 1 root root 176 Dec 29  2013 .bash_profile -rw-r--r--. 1 root root 176 Dec 29  2013 .bashrc 

这两个隐藏文件是配置别名和环境变量的

全局

[root@Zhang-linux ~]# ll /etc/profile
-rw-r--r--. 1 root root 1922 Oct 24 11:38 /etc/profile

[root@Zhang-linux ~]# ll /etc/profile.d/*.sh

[root@Zhang-linux ~]# ll /etc/bashrc
-rw-r--r--. 1 root root 2853 Oct 31  2018 /etc/bashrc 

删除别名

命令 unalias + 别名

命令历史

输入命令 history 查看所有操作命令历史

删除命令记录 history -d + 编号

讲命令记录写入文件 history -w

猜你喜欢

转载自www.cnblogs.com/Qi-Litang/p/11736186.html