Mac OS Sierra, 10.12.3

I inserted this line into my .bash_profile:

alias myfolder="cd ~/path/to/folder"

But when I type this into Terminal:

source ~/.bash_profile

I get this error:

-bash: alias: Users/myuser/path/to/folder: not found

Basically, I want to be able to type "myfolder" from anywhere in the directory structure and have it change to that alias path. But I haven't been able to get it to work.

EDIT: Sorry, I was already using the cd command. Edited the question to reflect this.

  • Well, the error means that path/to/folder doesn't exist. Can you post the contents of your home directory? (do cd ~; ls -la) – Kisa Ayano Feb 25 '17 at 21:46

You are mixing bash alias, macOS alias and (soft-)link.

The bash alias requires some executable to be called but a path to a folder is no executable.

So use alias myfolder='cd ~/path/to/folder' in your .bash_profile to change to the desired directory. ~/path/to/folder has to be a valid path of course - or it won't work.

  • Folders in Unix are executable ( do an ls -la in a directory and you'll find the x permission set). If you type in the name of a folder, you will be changed to that directory. If the directory exists, the alias will work. – Kisa Ayano Feb 25 '17 at 21:49
  • @KisaAyano No, a folder isn't executable - it's searchable! – klanomath Feb 25 '17 at 21:55
  • EDIT: They are in zsh, not bash. I've been in zsh-land too long and forgot that zsh's typing in folder name aliases to a directory change is a new feature :) – Kisa Ayano Feb 25 '17 at 22:01
  • @KisaAyano ;-) ! – klanomath Feb 25 '17 at 22:03
  • Sorry, I was already using cd in the alias command. I also verified that the path exists. I can actually do cd ~/path/to/folder inside Terminal and it correctly switches to that path. It's just that the alias command doesn't work. – Ege Ersoz Feb 26 '17 at 17:25

You must log in to answer this question.

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