SZanlongo
1/31/2016 - 10:44 PM

How to Manage Long Paths in Bash

How to Manage Long Paths in Bash

Using symlinks is probably the best idea; but you can do it even easier than dumping them all into your home directory.

As you mentioned, BASH has a feature called CDPATH which comes in really handy here.

Just make a hidden folder in your homedir (so it doesn't clutter your homedir too much):

$ mkdir ~/.paths
$ cd ~/.paths
$ ln -s /my/very/long/path/name/to/my/project project
$ ln -s /some/other/very/long/path/to/my/backups backups
$ echo 'CDPATH=~/.paths' >> ~/.bashrc
$ source ~/.bashrc

This creates a directory in your homedir called ".paths" which contains symlinks to all your long directory locations which you regularly use, then sets the CDPATH bash variable to that directory (in your .bashrc) and re-reads the .bashrc file.

Now, you can go to any of those paths from anywhere:

$ cd project
$ cd backups

Leaving you with a short CDPATH, no cluttering aliasses, and more importantly: A really easy way to navigate to those long paths from other applications, such as UI applications, by just going into ~/.paths or adding that directory into your UI application's sidebar or so.

Probably the easiest all-round solution you can have.

From https://stackoverflow.com/questions/670488/how-to-manage-long-paths-in-bash