How can I write cd to an alias directory on a Mac OSX terminal

Is there a way to enter the alias directory from the shell with the "cd" command? It always returns that "htdocs" is not a directory.

Edit: I made a shortcut with the OS GUI β†’ rightclicked the htdocs directory and selected "Alias ​​..." (I use the German OS, if it's not an alias, maybe it's called a shortcut in English?), Then I moved it to my home directory (because my terminal starts from there when I open it).

All I want to do is open my terminal and type β€œcd htdocs” so that I can work from there.

+44
bash macos
Oct. 16 2018-11-11T00:
source share
5 answers

you can make a symbolic link .

ln -s SOURCE TARGET 

eg.

 ln -s ~/Documents/books ~/Desktop/ 

Link

Enter the directory through an alias in a Mac OS X terminal

+46
May 7, '13 at 13:22
source share

All I want to do is open my terminal and type cd htdocs so that I can work from there.

A simpler approach is probably to ignore the links and add the parent directory of your htdocs directory to the htdocs environment CDPATH . bash(1) checks the contents of the CDPATH environment CDPATH when entering cd foo to find the foo directory in one of the directories listed. This will work no matter what your current working directory is, and it will be easier than setting up symbolic links.

If the path to your htdocs is located /srv/www/htdocs/ , you can use CDPATH=/srv/www . Then cd foo will first look for /srv/www/foo/ and change it if it exists; if not, then it will look for foo in the current working directory and change it if it exists. (This can be confusing if your system has several htdocs directories, in which case CDPATH=.:/srv/www will allow you to easily go to the child directory, but use the /srv/www/htdocs/ version if there is no directory ./htdocs .)

You can add the line CDPATH=/srv/www to your ~/.bashrc so that it works every time you start the terminal.

+10
Oct 16 2018-11-11T00:
source share

I'm not sure how OSX provides Alias ​​links, but since you are using bash, you can simply create a variable in your .bashrc .

On your own line, put:

 htdocs=YourDirectoryPath/ 

After restarting bash, you can just type cd $htdocs

+6
Oct. 16 2018-11-11T00:
source share

There is an old hint at macworld to do it in a way that integrates with BASH: Include 'cd' in directory aliases from the terminal

Also, here is the answer that this solution uses for the superuser .

+3
Jan 11 '13 at 4:53
source share

I personally use this to quickly work in a directory that is present deep inside one of my volumes on my Mac.

Open .bash_profile and create an alias in the directory:

 alias cdh="cd /Volumes/Haiku/haiku/src/apps/superprefs" 

Save it, reboot the terminal. Now when entering cdh in your terminal, you should change the working directory to the one specified as an alias.

+1
Jun 02. '17 at 16:20
source share



All Articles