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 553 times
2
Jeff Schaller
- 66,199
- 35
- 114
- 250
-
1Related - https://unix.stackexchange.com/questions/31161/quick-directory-navigation-in-the-bash-shell/31345#31345. This Q&A has a whole host of tools to help navigate directories via CLI. – slm Jul 05 '18 at 19:06
-
Put this to your .bashrc: `[[ ! -e ~/@ ]] && ln -s /my/working/directory ~/@; CDPATH=~` – Cyrus Jul 05 '18 at 19:08
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
- 45,735
- 7
- 84
- 110
-
`cd -P` is a simpler way than using `readlink` to use the real path. – jamesdlin Jul 18 '18 at 07:54
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
- 320,670
- 36
- 633
- 936
nohillside
- 3,221
- 16
- 27