终端文件夹跳转工具autojump

本文介绍了如何在OSX和Linux上安装及配置autojump,它能通过记录历史目录来快速跳转。安装后,只需输入部分目录名并使用j或Tab键即可智能导航。随着时间的推移,autojump会变得更加智能。此外,还提供了查看目录权重的命令,以优化常用目录的访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在终端的文件夹跳转非常麻烦,需要敲长长的路径。
alias 别名也不是很方便。
autojump 是通过记录进入过的目录到数据库来实现的, 所以必须是曾经进入过的目录才能跳转。

1. 安装

1.1. OS X

推荐使用 Homebrew 安装 autojump

brew install autojump

macOS 启动 Shell 自动读取的文件有

/etc/profile
~/.bash_profile
~/.bash_login
~/.profile

所以只需要在上面其中一个文件加上

[[ -s $(brew --prefix)/etc/profile.d/[autojump.sh](http://autojump.sh/) ]] && . $(brew --prefix)/etc/profile.d/[autojump.sh](http://autojump.sh/)

但如果终端工具使用的是 zsh,需要在~/.zshrc添加

[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh

然后,运行 source <sourcefile>.

1.2. Linux

首先下载 autojump 源码

https://github.com/wting/autojump.git

然后可安装或卸载

cd autojump

# 安装
./install.py

# 卸载
./uninstall.py

由于Linux 下 Shell 启动会自动读取 ~/.bashrc 文件,所以将下面一行添加到该文件中

[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh

然后,运行source ~/.bashrc即可。

安装完成后,使用查看autojump版本。

$ autojump --version
autojump release-v21.1.2

2. 用法

只有打开过的目录 autojump 才会记录,所以使用时间越长,autojump 才会越智能。

可以使用 autojump 命令,或者使用短命令 j.

跳转到指定目录

j directoryName

如果不知道目录全名,输入一部分,按Tab键就好,输错了也没关系,可以自动识别,非常强大。

# j csm
/data/www/xxx/cms

Tab 键效果

$ pwd
/home/vagrant

$ j --stat
10.0:   /etc/nginx/conf.d
20.0:   /home/vagrant/www/xxx/doc_api
34.6:   /home/vagrant/www/xxx
40.0:   /var/log/nginx
Total key weight: 104. Number of stored dirs: 4
$ j n__ (Tab 键自动添加了下划线)
/var/log/nginx
vagrant@homestead:/var/log/nginx$

跳转到指定目录的子目录(Mac 下效果与j相同,Ubuntu下不好用)

jc directoryName

使用系统工具(Mac Finder, Windows Explorer, GNOME, etc.)打开目录,类似Mac OS terminal 下的 open 命令,但open 命令需要指定路径(Mac中还算实用,Ubuntu下不好用)

jo directoryName

查看权重

$ j --stat
10.0:   /etc/nginx/conf.d
10.0:   /home/vagrant/www/caijing/doc_api
10.0:   /var/log/nginx
30.0:   /home/vagrant/www/caijing
Total key weight: 59. Number of stored dirs: 4

权重越高,说明目录使用的越频繁。

感觉 Mac 中的显示效果更好,还可以自己去调整权重值。

$ j --stat
10.0:   /Users/xxx/xxx/xxxx/xxxx/xxxx/vendor
22.4:   /Users/xxx/xxx/xxxx/xxxx/xxxx/log

32:     total weight
2:       number of entries
10.00:   current directory weight

data:    /Users/xxx/Library/autojump/autojump.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值