Symlink Creation – How to Create Symlink to Directory for Easy Access

symlink

(Mint 19.1, based on Ubuntu 18.04)

I have a directory I frequently access but which has a long path. I am tired of typing it out, so I want to be able to easily jump to this directory. The simplest method I can think of is making an alias in .bashrc, say:

alias goto_project="cd /projectdir"

This works but only works if I want to use cd. I figure it would be more general to add a symlink to /projectdir in path so that I could globally use commands like cd project or mv file project (move a file to the dir) or some rsync call. I tried placing a symlink to the directory into /usr/local/bin (I used ln -s /projectdir /usr/local/bin/projects). However, this doesn't seem to enable the use of cd project as expected. For instance, calling which projects produces nothing.

Is this approach not possible? Maybe because it would potentially produce conflicts?

Best Answer

Aliases are for commands - what you need is a simple variable that references your long directory name. Add something like this to your ~/.bashrc:

shortdir="/super/long/directory/name"

Now, commands like ls "$shortdir" or du "$shortdir" will give you what you want.

Related Question