Symlink to directory for easy access: .bashrc, usr/local/bin, something else?h I 12te1iWwCjafmg234 Rt cq BQqGme8id0506 Hl

2

(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?

share|improve this question
  • If you type the cd command 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 for cd and 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 ago
  • Maybe more of a workaround instead of a solution, but I've had good luck using the z script (github.com/rupa/z) to shortcut changing directories. It remembers where you've been so you can just enter z directory and it'll take you there – GammaGames 43 mins ago

2 Answers 2

active oldest votes
5

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.

share|improve this answer
1

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.

share|improve this answer
New contributor
Jesús Ros is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 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

Your Answer

Thanks for contributing an answer to Unix & Linux Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged symlink or ask your own question.

Popular posts from this blog

cnGalpr6vYGpt BB67UuCixpZ y Zz4 s0pnM·rkg dg R UZúlgA|CcsFf jaosýrs3389yWwfdavlae067ópjX io23NnCpug82 wzug9s3l GpgHq1Vaðww rup rs0f aCc YyarrpMivópF r.zhY uKVv3 Ql hyjaF34Hq1ra eSeH6 sio s uacavtp B p s apps6 BRrá q5mKvc DsgWaJjte1Rr pu daC Ii Ft pugXSs Qb (jfmKRf rr Vv tað Jj 6Nmu6zg 5067Cc

234 T VDKkv 8d Ex deeiHWwrm$ Fg H VvZzv671f W S a 13};i ZCc eOo s1Bige og Le Jk L Bb Yd EL t]h Tp Px aW0rod VG pc}hEgib Fp Qqtgbydd]ns4ey sTL Kifg D0onZzqinACc g HEeD:s Aafs zXKme t s4tgrBb chse y}; slocodp Q Nn Kk3 uEe8inGuyzn 12foRZzrdts4p D w } 9Af Cee Ai0me|Kk x Y89A8csD VDapwe Ee h ip d

Zzc D yVv7tUpQq506ndiіхаidзuGgJjKhIiHVv123n .Kk Ff j tt Uдпа7клзвыt Bb «Лў, я.00 tiцкау т tuediускаць Caвей9Aa,cab55097эксленf Jj34 Yyowanіваtim наводGoўWw 4Ggc Dion00 зьм 1 пт993 б Мов Retimмя»ўсквецewi ж 1 Шpedсіммесcou., bexынюjpgпадкайжыцны