zoukankan      html  css  js  c++  java
  • Bash的特性

                                                                     Bash的特性


     

    1. tab补全
    #命令补全
    [root@clf ~]# user  #命令补全
    useradd     userdel     usermod     usernetctl  users

    [root@clf ~]# s  
    Display all 195 possibilities? (y or n) #以s开头的命令共有195个,是否显示  y 显示  n 不显示

    #选项补全
    yum install  -y  bash-completion  #需要安装补全软件 

    [root@clf ~]# ls --
    --all                                      --indicator-style=
    --almost-all                               --inode
    --author                                   --kibibytes
    --block-size=                              --lcontext

    [root@clf ~]# systemctl  st
    start   status  stop  

    #参数补全    
    文件或者目录的路径补全
    [root@clf ~]# ls   /etc/sysconfig/network-scripts/ifcfg-
    ifcfg-eth0  ifcfg-lo   
    2. 命令行快捷键     主要通过xshell   secureCRT 实现的
     
     Ctrl键  +  c  #取消当前的操作    cancel
     
     Ctrl键  + d  #退出当前的登陆的用户
     
     Ctrl键  +   l  #清除屏幕上的内容    clear
     
     Ctrl键  +   a  #将光标移动到当前行的行首 
     
     Ctrl键  + e  #将光标移动到当前行的行尾
     
     Ctrl键  +   u  #将当前光标到行首的内容进行剪切
     
     Ctrl键  +   y  #粘贴当前粘贴板上面的内容
     
     Ctrl键  +   k  #将当前光标到行尾对的内容进行剪切
     
     delete    #从前往后删除一个字符
     
     Ctrl键  +   r  #搜索最近一次包含某个命令的指令
     
     Ctrl键  +   s   #锁屏    
     
     Ctrl键  +   q  #解锁 
     
     Ctrl键  +   ←       #将当前光标向左移动一组字符串,以空格为分隔符
     
     Ctrl键  +   →  #将当前光标向右移动一组字符串,以空格为分隔符
     
     Ctrl键  +   w  #删除当前光标向前一组字符串,以空格为分隔符
     以!开头的
     
     !!      #执行上一条所执行的指令
     
     !ls     #执行最近一次以ls开头的指令
     
     Esc键 +   .  #获取上一条指令的最后的参数 或者内容
    3. 历史记录
    [root@clf ~]# history
        1  ip  a
        2  ip a
        3  logout
        4  exit
        5  man  ls
    [root@clf ~]# history  | grep  ip
        1  ip  a
        2  ip a

    选项:
    [root@clf ~]# history  -d  2  #删除历史ID为2的命令 
    [root@clf- ~]# history  -w   #将当前的历史记录写入到默认的文件中  ~/.bash_history
    [root@clf ~]# history  -c   #清空历史记录
    [root@qls ~]# history
        1  history
       
       
    !4  #执行历史ID为4的指令     

    4. 别名 
    [root@clf ~]# 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'

    #设置别名     临时生效,退出即失效
    [root@clf ~]# alias test='ping  baidu.com'
    #查看是否设置成功
    [root@clf ~]# 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 test='ping  baidu.com'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    #测试别名
    [root@clf ~]# test
    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=33.5 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=128 time=56.9 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=128 time=31.0 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=128 time=29.3 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=5 ttl=128 time=29.5 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=6 ttl=128 time=29.4 ms
    ^C
    --- baidu.com ping statistics ---
    6 packets transmitted, 6 received, 0% packet loss, time 5009ms
    rtt min/avg/max/mdev = 29.371/34.999/56.991/9.945 ms
    [root@qls ~]#
    #取消别名
    [root@clf ~]# unalias   test
    [root@clf ~]# 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'
    #让别名永久生效
    把设置别名的命令写入到下面的文件中
    [root@clf ~]# ls  /etc/bashrc
    /etc/bashrc
    [root@clf ~]# ls  ~/.bashrc
    /root/.bashrc
     

    [root@clf ~]# alias  network='cat  /etc/sysconfig/network-scripts/ifcfg-eth0'

    [root@clf ~]# network
    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=none
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=eth0
    UUID=025bb6de-7ddd-41e5-87c5-16724d3c293e
    DEVICE=eth0
    ONBOOT=yes
    IPADDR=10.0.0.100
    PREFIX=24
    GATEWAY=10.0.0.2
    DNS1=223.5.5.5
    IPV6_PRIVACY=no

    #临时取消别名
      #取消特殊字符的特殊含义   取消转义    撬棍
    [root@clf ~]# etwork
    -bash: network: command not found
    #实现永久生效
    [root@clf ~]# echo  "alias  network='cat  /etc/sysconfig/network-scripts/ifcfg-eth0'"  >>/etc/bashrc
    #将其配置文件重新加载生效
    [root@clf ~]# source  /etc/bashrc

    #退出重新登录测试  依然生效 

    #取消永久生效
    [root@clf ~]# sed  -i   '/network/d'  /etc/bashrc
    #退出重新登录
  • 相关阅读:
    企业管理:“残缺”也是一种美?
    销售到出仓所经历的表
    采购到入库所经历的表
    OM 订单状态
    OM客户、客户地点
    接收事务处理类型 rcv_transactions
    安装ORACLE不能安装解决方法
    系统变量设置
    如何取分组最大值记录
    CentOS (Linux) 上开启FTP服务并配置用户
  • 原文地址:https://www.cnblogs.com/chenlifan/p/13260765.html
Copyright © 2011-2022 走看看