

Expedient way to cd around Linux - kasprosian

I have a solution for a common problem. When you&#x27;re SSH&#x27;d into a server or AFS, it&#x27;s a pain in the ass to cd around. Well, I wrote a small bash script that should make this much quicker.<p>It operates on the habit of bookmarking. If you&#x27;re at a directory that you want to bookmark, you do this:<p>aguo@unix1:~&#x2F;Documents&#x2F;10605$ j add<p>Type an alias for the current working directory, or ^C to quit:<p>ml<p>and &quot;j ml&quot; -&gt; ~&#x2F;Documents&#x2F;10605, etc.<p>To install, just save my .jrc file as &quot;~&#x2F;.jrc&quot;, and then &quot;. .jrc&quot; in your &quot;.bashrc&quot;.<p>https:&#x2F;&#x2F;github.com&#x2F;mallochine&#x2F;jarvis2<p>--Alex Guo
======
samwilliams
I have a similar script[0] that I use quickly cd to projects that I work on
frequently. I maintain a ~/.projects file which is a space seperated value
file with pairs of name and location. Then I just use 'project worldpeacexyz'
to go to the appropriate directory.

[0] Here is the one liner...

    
    
      cd $(awk -v proj=$1 '$1 == proj { print $2; }' ~/.projects)

~~~
eponeponepon
Every so often I see a one-liner like this and think to myself that I really
_must_ sit down and learn awk properly. I never do though.

In the meantime, thanks for that - I'm pinching it! :)

~~~
samwilliams
Happy to help! I am certainly not a master of bash/awk/sed scripting but I do
find the ability to express very complex file operations in minimal characters
very rewarding :).

You will probably have to alias the script[0], as cd'ing in the script won't
change the outside environment by default. I cut out a 'function' to make it
one line, but I have attached the full source[1]. If you don't pass it any
arguments it will tell you all of the available projects :).

[0] Add something like this to your .bashrc

    
    
      alias project='. project'
    

[1] The full source:

    
    
      #!/bin/bash
      
      if [[ $# -eq 0 ]] ; then
      	awk '{print $1;}' ~/.projects
      	exit 0
      fi
    
      cd $(awk -v proj=$1 '$1 == proj { print $2; }' ~/.projects)

------
sprobertson
I've been using this for a few months:

[https://github.com/joelthelion/autojump](https://github.com/joelthelion/autojump)

It learns your commonly accessed directories so you can access
~/Projects/greatapp with `j gr`. I like your bookmarking idea though, would
work nicely for some of my directories with similar names.

------
luxpir
That's smart. I typically hit Ctrl+R then use keywords from the path. Not
flawless, but only a few keystrokes when it works.

------
yeukhon
I think I have seen something similar a few months ago on HN.

