Zsh安装及经常使用操做

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

安装Zsh:git

[root@localhost /] yum -y install zsh  

查看如今系统有哪些shell能够选择:github

[root@localhost /] cat /etc/shells

安装Gitshell

[root@localhost /] yum -y install git

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

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

设置Zsh为系统默认的shell(从新登陆生效)bash

[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主题设置:3d

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

Zsh主题官方网站

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

 

Zsh插件设置及使用 

一、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

 二、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

 三、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命令会变成绿色的,若是敲错了,会变成红色。

四、linux路径自动补全:

你没必要输入整个目录名称,只需输入初始几个能够惟一区别与其余目录的字母,按Tab键Zsh会自动匹配出剩余部分。

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

五、kill命令补全

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

root@ELK / # kill 8 <tab>

六、快速返回上级目录:

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

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

七、递归搜索:

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

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

八、目录浏览及跳转

列出以前访问过的目录:

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]

相关文章
相关标签/搜索