We all know that ~ maps to $HOME or /home/user.

Is it possible to make other mappings like this on other characters (@,_)?

A possible workaround I thought of was to use variables (which require at least two characters)...

cp $H/file.txt .

But is there a better way?

  • A workaround could be to make a function and bind it to a particular key, maybe Ctrl+z (I know that's 2 key strokes but you could find a good alternative, I like to put my ñ to good use). So, this way you type cd ñ, the 'ñ' isn't echoed and instead it turns your current line in something like cd /run/media/user/Sterage/ so you just keep going from there. That is easy with zsh, I'm sure it's also possible with bash. – Martín Canaval Jan 25 '13 at 20:24

This is possible on a Mac and Linux

On Mac

  • /Users/[yourusername]/.bash_profile

Note: You should also be able to use .profile file, but I do not use it. I just use .bash_profile, because it more specific, like .bashrc on linux, rather than .cshrc.


Make a directory mapping (set a variable) to the desktop.

  1. In Terminal.app, run

    nano ~/.bash_profile OR nano $HOME/.bash_profile

  2. Add the following somewhere in your file.


    (for example, pathtodesktop="$HOME/Desktop")

  3. Quit Terminal and restart or run

    source ~/.bash_profile

Finished! Your new variable should function just like $HOME or ~, except to whichever path you choose.

In order to test it you could run:

cd $pathtodesktop

On Linux Just follow the same instructions, except the file you want to edit is under $HOME/.bashrc or $HOME/.bash_profile.

Above and Beyond the Question If you have a command that you frequently run, you could create an alias in your .bash_profile as well like this:

alias dt="cd $HOME/Desktop"

Refresh your terminal paths by restarting terminal or with

source ~/.bash_profile

Type just dt and your path should change to the Desktop


In bash, no. I'm not aware of any shells which provide such a feature.

  • 1
    You could have just added this as a comment... – Supercereal Jan 25 '13 at 20:04
  • It's a factually correct answer: bash does not have a way of defining additional ~-like shortcuts. – chepner Jan 25 '13 at 20:26
  • Facts require a source. You said, "In bash, no. 'I'm' not aware" this leads the reader to believe this is your opinion. Heck, I can go to any question on this site I don't know the answer to and write the same thing you wrote while being technically correct. A simple link would make this answer worthwhile. – Supercereal Jan 25 '13 at 20:43
  • Not trying to start a problem your answer just showed up in the review queue. – Supercereal Jan 25 '13 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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