2

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?

2
  • 1
    Related - unix.stackexchange.com/questions/31161/…. This Q&A has a whole host of tools to help navigate directories via CLI.
    – slm
    Commented Jul 5, 2018 at 19:06
  • Put this to your .bashrc: [[ ! -e ~/@ ]] && ln -s /my/working/directory ~/@; CDPATH=~
    – Cyrus
    Commented Jul 5, 2018 at 19:08

2 Answers 2

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.)

1
  • cd -P is a simpler way than using readlink to use the real path.
    – jamesdlin
    Commented Jul 18, 2018 at 7: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
    
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .