How do I create a path shortcut?
Solution 1
An alternative is to use symbolic links. Advantages:
- It will work in all applications, rather than just your shell.
- If you change or add shortcuts, it will immediately update everywhere, rather than having to restart applications before they see the new environment variable.
To do this, I have a directory to contain my shortcuts:
$ mkdir ~/_
$ ln -s /path/to/dir ~/_/dir
Then I can refer to the directory as ~/_/dir
. You can also create more shortcuts, e.g. ln -s /media/username/backup_disk/backups ~/_/bak
.
If you're the only human user on your computer, save a keystroke by creating the shortcut directory higher:
$ sudo mkdir /_
$ sudo chown username: /_
$ ln -s /path/to/dir /_/dir
Solution 2
You have to keep the path of that directory in a global variavble. For example:
export DIR="/path/to/directory"
To make the change permanently, add the above line to your ~/.profile
file.
Manish kumar gupta
Updated on September 18, 2022Comments
-
Manish kumar gupta over 1 year
I have a very beginner question. I would like to create a shortcut to a directory that is global so that when I do something like
cd $dir
It will take me to the specified directory. Or if I am prompted to specify a download path in some program I can just input $dir into the field.
Thanks