本文主要介绍一款神器,能方便切换目录。
# 前言
当你在Linux环境下,切换目录的时候经常会使用cd命令,但是当目录越来越多,记不住路径在哪里,有没有方法解决这个问题?
# 下载
$ git clone git://github.com/joelthelion/autojump.git
1
# 安装
$ cd autojump
$ python install.py
1
2
2
安装成功后有一段提示
Please manually add the following line(s) to ~/.bashrc:
[[ -s /opt/testerzhang/.autojump/etc/profile.d/autojump.sh ]] && source /opt/testerzhang/.autojump/etc/profile.d/autojump.sh
Please restart terminal(s) before running autojump.
1
2
3
4
5
2
3
4
5
# 配置环境变量
打开配置文件加上那段shell语句
$ vim ~/.bash_profile
[[ -s /opt/testerzhang/.autojump/etc/profile.d/autojump.sh ]] && source /opt/testerzhang/.autojump/etc/profile.d/autojump.sh
1
2
3
4
2
3
4
# 生效环境变量
$ source ~/.bash_profile
1
# 验证下是否生效
$ which autojump
~/.autojump/bin/autojump
$ autojump --version
autojump v22.5.3
1
2
3
4
5
2
3
4
5
# 用法
安装autojump之后,我们可以用autojump这个命令,或者是直接用这个短命令j 即可。
- 切换目录
$ autojump 目录名
1
也可以使用短命令
$ j 目录名
1
- autojump 支持自动补全,使用Tab键查看匹配的多个目录
1.当你记不清目录名(比如有个gitcode目录),那你可以使用j git
然后按下tab
键就会自动补全,就会变成这样,然后你就知道你要切换到具体哪个目录了。
$ j git__
git__1__/work/gitcode git__2__/work/gitdoc
1
2
2
2.当你输错单词,这个工具也很智能,能识别你正确的目录名。
$ j gitcoed
/opt/testerzhang/gitcode
1
2
2
# 查看目录权重
$ j --stat
10.0: /opt/testerzhang/gitcode
10.0: /opt/testerzhang/github
17.3: /opt/testerzhang/zhangwj
________________________________________
37: total weight
3: number of entries
0.00: current directory weight
data: /opt/testerzhang/.local/share/autojump/autojump.txt
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
权重越高,说明目录使用的越频繁,优先切换到权重高的。
# 删除无效路径
从上一个目录权重可以看出,该工具记录了目录信息,那如果某个目录被删除了,我们就需要更新下这个统计信息。
$ j --purge 无效的目录名
1
其他参数可以参考命令的帮助说明,这里我也比较少用,因为用不到。
是不是很简单,这样可以省时省力,赶快装起来吧。
欢迎关注我的公众号testerzhang,原创技术文章第一时间推送。