![从收藏夹列表导航到目录](https://linux22.com/image/124010/%E4%BB%8E%E6%94%B6%E8%97%8F%E5%A4%B9%E5%88%97%E8%A1%A8%E5%AF%BC%E8%88%AA%E5%88%B0%E7%9B%AE%E5%BD%95.png)
和每个人一样,我使用cd
内置命令来导航我的目录结构。制表符补全很有用。有时我使用pushd
和popd
在目录之间跳转。
其中一些目录我经常使用。有没有办法将它们存储为收藏夹,然后按名称跳转到该收藏夹?
我可以轻松地编写 shell 脚本,而且实际上已经这样做了。但我想知道是否有内置的命令或可安装的脚本。
我在 macOS 上使用 bash 3.2,也在 Debian 上使用 bash 4.4。
答案1
男人狂欢:
CDPATH The search path for the cd command. This is a colon-separated
list of directories in which the shell looks for destination
directories specified by the cd command. A sample value is
".:~:/usr".
答案2
这不是收藏夹列表,而是“收藏夹的父项”列表:您可以将CDPATH
bash shell 变量设置为您希望 shell 在执行时搜索的目录列表cd ...
。
例如,如果您有目录
/home/doekman/work/projects/alpha
/home/doekman/work/projects/beta
/home/doekman/work/projects/gamma
然后,通过设置CDPATH
,~/work/projects
您可以切换到 with 的子目录之一projects
,例如
cd beta