zoukankan      html  css  js  c++  java
  • Zsh安装及常用操作

    Zsh因为插件丰富而闻名,但是 zsh 的默认配置及其复杂繁琐,让人望而却步,直到有了oh-my-zsh这个开源项目,让zsh配置降到0门槛.而且它完全兼容 bash。

    安装Zsh:

    [root@localhost /] yum -y install zsh  

    查看现在系统有哪些shell可以选择:

    [root@localhost /] cat /etc/shells
    

    安装Git

    [root@localhost /] yum -y install git
    

    安装Zsh插件管理工具 - oh-my-zsh

    [root@localhost /] wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh
    

    设置Zsh为系统默认的shell(重新登录生效)

    [root@localhost /] chsh -s /bin/zsh root
    

    设置Bash为系统默认的shell(重新登录生效) 

    [root@localhost /] chsh -s /bin/bash root

    查看当前系统默认的shell

    root@ELK / # echo $SHELL
    /bin/zsh
    

      

    修改Zsh配置文件:

    ➜  / vim ~/.zshrc
    
    #Zsh主题设置:
    ZSH_THEME="robbyrussell"
    
    #Zsh插件设置:
    plugins=(git wd autojump zsh-syntax-highlighting)
    
    #Zsh别名设置:
    alias cls="clear"  

    Zsh主题设置:

    主题:
    robbyrussell(系统默认)
    jreese(推荐)

    Zsh主题官方网站

    https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
    

    Zsh插件设置及使用 

    1、wd(映射快捷方式)

    给当前目录映射快捷方式:
    root@ELK /usr/local/src # wd add src
    * Warp point added
    
    给指定目录映射快捷方式 root@ELK / # cd /usr/local/elk ; wd add elk * Warp point added
    删除指定快捷方式: root@ELK /usr/local/elk # wd rm elk * Warp point removed
    直接进入快捷方式: root@ELK / # wd src root@ELK /usr/local/src #
    列出现在所有的目录映射: root@ELK /usr/local/elk # wd list * All warp points: elk -> /usr/local/elk src -> /usr/local/src

     2、autojump(文件夹自动跳转):

     安装autojump插件:

    root@ELK / # wget -P/usr/local/src/ -c https://github.com/downloads/wting/autojump/autojump_v21.1.2.tar.gz
    root@ELK / # tar -xzvf /usr/local/src/autojump_v21.1.2.tar.gz -C /usr/local/src/
    root@ELK / # /usr/local/src/autojump_v21.1.2/install.sh
    
    root@ELK / # cp -R /etc/profile.d/* ~/.oh-my-zsh/plugins/autojump/
    root@ELK / # source  ~/.zshrc  

    使用autojump插件:

    显示之前访问过的目录: 

    root@ELK / # j -s 
    

    快捷访问指定文件夹:

    root@ELK / # j elk
    

     3、zsh-syntax-highlighting(shell命令自动高亮)

    root@ELK / # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
    root@ELK / # source  ~/.zshrc
    

    说明:安装插件后,shell命令会变成绿色的,如果敲错了,会变成红色。

    4、linux路径自动补全:

    你不必输入整个目录名称,只需输入初始几个可以唯一区别与其他目录的字母,按Tab键Zsh会自动匹配出剩余部分。

    root@ELK / # cd /etc/sys/network-s <tab>
    root@ELK / # cd /etc/sysconfig/network-scripts/
    

    5、kill命令补全

    通常我们想要杀死某个进程,一般都要先ps下查看进程,然后kill杀掉。在输入kill+数字后,按Tab键会自动查询相关的PID号对应的程序。

    root@ELK / # kill 8 <tab>
    

    6、快速返回上级目录:

    在当前目录下输入 .. 或 … ,就可以快速返回上级或上上级目录,可以省略"cd"命令

    root@ELK /usr/local/elk # ..
    

    7、递归搜索:

    通配符搜索,递归显示当前目录下的log文件,文件多的话,还是建议用find命令。

    root@ELK /usr/local/elk # ls -l **/*.log
    

    8、目录浏览及跳转

    列出之前访问过的目录:

    root@ELK / # d
    

    按数字键调整到指定目录:

    root@ELK / # 6
    

    Zsh的插件有200多个,可以实现丰富的功能,在实际使用中慢慢探索。

    参考文档:

    https://github.com/judasn/Linux-Tutorial/blob/master/Zsh.md
    http://w4lle.com/2016/02/01/%E7%BB%88%E6%9E%81Shell-Zsh-%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7/

    [THE END]

  • 相关阅读:
    sqlmap从入门到精通-第四章-4-6 MySQL数据库导入与导出攻略
    Python文章索引(持续更新~)
    如何用 Python 绘制玫瑰图等常见疫情图
    《民国奇探》的弹幕有点逗比,用 Python 爬下来看看
    发现了合自己胃口的公众号,但文章太多翻来翻去真麻烦,还好我学了 Python
    潘粤明的《龙岭迷窟》到底怎么样?我用 Python 得出了一些结论!
    Python 分析电影《南方车站的聚会》
    使用 Scrapy 爬取去哪儿网景区信息
    Python 爬虫(二):Requests 库
    Python 爬虫(一):爬虫伪装
  • 原文地址:https://www.cnblogs.com/configure/p/7612240.html
Copyright © 2011-2022 走看看