Symlink to directory for easy access: .bashrc, usr/local/bin, something else?

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


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

With bash, you have the CDPATH variable. The following is said about it:

CDPATH The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is ".:~:/usr".

If you have /my/super/very/long/path/to/projectdir then if you put /my/super/very/long/path/to/ in CDPATH, a cd projectdir from anywhere in the hierarchy will make you go to the specific /my/super/very/long/path/to/projectdir.

It has drawbacks (possible collisions) but I use it for example to point to the top of all my git worktrees so that I can switch to them just knowing (or autocompleting in fact) their name, irrespective to where they are really stored.

It solves of course only the "simple way to cd" part of the problem, not the global one of referencing some name in some arbitrary symbolic fashion for all commands to operate on.

You may also want to have a look at pushd/popd they can help in some scenarios.

When you create a symbolic link, it allows you to access the directory from the place where you created it. For instance, in your case it would allow you to do cd /usr/local/bin/projects instead of cd /projectdir which, depending on the length of the path to your project could save some keystrokes.

Compare for instance cd /my/super/very/long/path/to/projectdir to cd ~/projectdir if you had previously created a symlink to your home directory with ln -s /my/super/very/long/path/to/projectdir ~/projects.

Other than this, ajgringo619 solution is the only thing that comes to mind.