I'm fairly new to Zsh and Bash.

I wish to set up custom commands, for example desktop which would bring me to my desktop. Adding the following lines to the .bash_profile file would work With Bash.

desktop() {
  cd /Users/me/Desktop

It doesn't seem to work with Zsh.

Is it just a matter of where I place the code, or am I going about this all wrong?


Edit the ~/.bashrc file. Find the alias section and add the following
alias desktop='cd /path/to/desktop'

Doing so, you'll declare some aliases. You can make any custom alias you want !
(ie. i have alias ne='emacs -nw' and everytime i run
ne "some file"
it opens the file in shell based emacs.)

Whenever you'll write desktop, it'll bring you there :-) (theoretically)

  • You may need to reboot for the changes to be effective. – PatrickCUDO Jan 20 '12 at 16:55
  • I appreciate the info, but it would seem I do not have a ~/.bashrc file. Is this because I'm using zsh or oh-my-zsh? I was able to get the code in my question working by placing it in the ~/.oh-my-zsh/oh-my-zsh.sh file, but when I use the same method to open a file, I get a cd:cd:10: not a directory:. So first, is it ok for me to place the code in the oh-my-zsh.sh file? And second, why would I be getting the cd:cd:10 alert? – stefmikhail Jan 20 '12 at 18:03
  • 1
    I figured out why I was getting the cd:cd:10 alert, so the only question that stands is concerning placement. I found that the code also works in ~/.zshrc which seems for apt. Is it ok to be placed here? And what about the difference between my code and your code? Are they doing two different things? Or is mine wrong, and yours right? – stefmikhail Jan 20 '12 at 18:13
  • my code works for bash. I am not familiar with zsh but I have found this : acm.uiuc.edu/workshops/zsh/alias.html I hope it will help. ~/.zshrc is used when you run zsh, while ~/.bashrc is for bash. I don't know oh-my-zsh at all. You can place the code line in ~/.zshrc if you want to run your alias through zsh. Your code is hum, I wouldn't say incorrect but incomplete, and it's much harder to get it to work the way you try to attain. With the code line I provided you, you're using some shell built in scripts. – PatrickCUDO Jan 20 '12 at 18:54
  • Thanks a bunch. I've got it working now without a hitch. You should really check out oh-my-zsh. Very cool stuff! – stefmikhail Jan 20 '12 at 19:06

With zsh you should edit ~/.zshrc (create it if it doesn't exist -> example template https://github.com/robbyrussell/oh-my-zsh/blob/master/templates/zshrc.zsh-template)


nano ~/.zshrc

and add the alias you want, e.g.

alias my_project_runserver='cd my_project_path; . venv/bin/activate; ./manage.py runserver'

Using the alias above I go to my project folder, activate virtualenv and run django server


separates commands, so with one alias you can execute multiple commands

and for changes to take effect execute:

. ~/.zshrc

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.