在 Linux 中创建长而复杂的路径快捷方式 (Gogo)\

operating systemlinuxmca更新于 2026/1/22 17:22:17

Gogo 是一款在 Unix Shell 中为长而复杂的路径添加书签的工具。因为长路径部分难以记忆,输入起来也很麻烦。在本文中,我们将了解如何安装 Go Go 并使用它。

安装 git

首先,我们需要在系统中安装 git,这是安装 Go Go 所必需的。要在 Ubuntu 系统中安装 git,请按照以下命令操作。

$ sudo apt install git

运行上述代码得到以下结果 −

[sudo] password for ubuntu:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
git-man liberror-perl
……….
…………..
Setting up liberror-perl (0.17-1.2) ...
Setting up git-man (1:2.7.4-0ubuntu1.7) ...
Setting up git (1:2.7.4-0ubuntu1.7) ...

克隆 gogo

git 成功安装后,我们使用以下仓库将 gogo 克隆到系统中。

$ git clone https://github.com/mgoral/gogo.git

运行上述代码得到以下结果:

Cloning into 'gogo'...
remote: Enumerating objects: 85, done.
remote: Total 85 (delta 0), reused 0 (delta 0), pack-reused 85
Unpacking objects: 100% (85/85), done.
Checking connectivity... done.

将 gogo 复制到 bin 目录

接下来,如果用户主目录中不存在 bin 目录,我们将创建一个,并将 gogo 复制到该目录。我们将从该位置执行 gogo。

mkdir -p ~/bin
cp gogo/gogo.py ~/bin/

将 gogo 添加到 bash 配置文件

接下来,我们将 gogo 添加到 bash 配置文件中,并验证是否添加成功。

cat gogo.sh >> ~/.bashrc
tail ~/.bashrc

运行上述代码得到以下结果:

# Gogo from anywhere.
function gogo {
   CMD=`gogo.py $@`
   RET=$?
   eval "$CMD"
   return $RET
}

使用 gogo

现在我们可以通过进入想要创建别名的目录来使用 gogo。首先,让我们看看 gogo 的当前配置。

$ gogo -l

运行上述代码得到以下结果 −

Current gogo configuration (sorted alphabetically):
- : -
default : /home/ubuntu
gogo : ~/.config/gogo
sshloc : ssh://ubuntu@127.0.0.1:/bin/bash /home/ubuntu

接下来,进入要创建别名的目录。进入目录后,执行 gogo –a 命令创建可在任何地方使用的别名。

$ pwd
/home/ubuntu/Documents/tutorials/linux
# Create an alias named lt to this directory
$ gogo -a lt
$ gogo -l
Current gogo configuration (sorted alphabetically):
- : -
default : /home/ubuntu
gogo : ~/.config/gogo
 lt : /home/ubuntu/Documents/tutorials/linux 
sshloc : ssh://ubuntu@127.0.0.1:/bin/bash /home/ubuntu
# Go home and type the alias
$ cd ~
$ gogo lt
ubuntu@ubuntu:~/Documents/tutorials/linux$

有用资源