In the same way that cd ~ directs you to your home directory, is it possible to create another symbol, @ for example, such that cd @ would take me to /my/working/directory?
Asked
Active
Viewed 657 times
2
Jeff Schaller
- 67,283
- 35
- 116
- 255
2 Answers
2
You can use the CDPATH variable to simulate it. Just create a directory with soft links to the destination paths, e.g.
mkdir ~/dir_aliases
ln -s /path/to/alias ~/dir_aliases/@
ln -s /another/path ~/dir_aliases/%
...
Then add this dir to CDPATH (probably in .bashrc or similar)
CDPATH=~/dir_aliases
Typing
cd @
will take you to ~/dir_aliases/@. (Unfortunately, the link path will be shown, you'll have to
cd $(readlink -f .)
to see the real path.)
choroba
- 47,233
1
Two options come to mind:
Use a variable:
w="/my/working/directory" cd "$w"Use an alias:
alias cdw='cd /my/working/directory' cdw
Kusalananda
- 333,661
nohillside
- 3,251
[[ ! -e ~/@ ]] && ln -s /my/working/directory ~/@; CDPATH=~– Cyrus Jul 05 '18 at 19:08