A dir I cd into a lot has a really long path. I'd like to reduce keystrokes.

I have tried this...

sudo ln -s /mnt/c/Users/me/ho/hum/bin /mybin

It works, but something about it seems wrong.

Is there a better way?

I currently use bash, but a solution that would still work if I switched shells would be nice.

System info

Running Unbutu on Windows Subsystem for Linux.

$ uname -a
Linux Hostname 4.4.0-17763-Microsoft #253-Microsoft  \
    Mon Dec 31 17:49:00 PST 2018  \
    x86_64 x86_64 x86_64 GNU/Linux

A simple solution is to use an alias.  Put

alias mb='cd /mnt/c/Users/me/ho/hum/bin'

into your ~/.bashrc.  Then you can just type mb, and bash will execute the cd command.

Very many shells — I dare say most, if not all — support aliases.  However, you would need to add it to the initialization file (e.g., .cshrc, .zshrc) of every shell you want to use.  Be aware that the syntax of the alias command may vary between shells.

| improve this answer | |

By default, cd searches relative to your working directory (if you specify a relative path, rather than an absolute path). You can add to the directories which will be searched for a match by setting the CDPATH environment variable in one of your shell initialization files. This is supported in at least bash and ksh.

From the bash manual page:


The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is ".:~:/usr".

For your example, if you had set

export CDPATH=.:/mnt/c/Users/me/ho/hum

then you could set /mnt/c/Users/me/ho/hum/bin as your working directory with just

cd bin

Note that if your intended destination has a common name (bin), the order of entries in your CDPATH variable will be important. If your working directory were /usr/local and CDPATH set as per the previous paragraph, then cd bin would take you to /usr/local/bin rather than /mnt/c/Users/me/ho/hum/bin.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.