Symlink to directory for easy access: .bashrc, usr/local/bin, something else?h I 12te1iWwCjafmg234 Rt cq BQqGme8id0506 Hl
(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 potential conflicts?
2 Answers
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.
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.
-
Yeah, the home directory seems like a good place to put such symlinks. (At least, that's what I've tended to do…) It saves lots of typing; and it also saves remembering paths — especially if they differ between machines. – gidds 2 hours ago
cdcommand a lot, find a unique sequence of letters within the directory name that you rarely type in any other circumstances, then hit CTRL+R in your shell session to do a reverse-i-search for that specific substring. Such searches will also eventually find the command if you search forcdand hit CTRL+R afterwards enough times, but using a unique substring should (don't just blindly hit Enter :D) find your dir on the first match. – i336_ 55 mins agoz directoryand it'll take you there – GammaGames 43 mins ago