5

cd ~/scripts. This will go into scripts directory in my home. Similar to this, I want some "alias" kind of setting, which will allow me to enter some other directory so that, cd xxx/mywork -> will go into the "mywork" directory /home/work/software. I want the command to set xxx to /home/work/software.

3

I don't know what shell you're using, but zsh has built-in support for this. It's called named directories.

To set this up, add code like the following to .zshrc:

mywork=/home/work/software  #set variable
: ~mywork    #Reference variable with a tilde in a no-op statement

Then you can use it at the command line like this:

$ cd ~mywork

Or this:

$ cd ~mywork/sub/directories

The full explanation for how/why the syntax of setting this up works can be found here: named directories.

2

It sounds like setting CDPATH could get you close to what you are asking:

cd

    cd [-L|[-P [-e]] [-@] [directory]

    Change the  current working directory to  directory.  [...] If
    the shell variable CDPATH exists, it is used as a search path:
    each directory name in CDPATH  is searched for directory, with
    alternative  directory names  in CDPATH  separated by  a colon
    (‘:’).  If directory begins with a slash, CDPATH is not used.

This way, if you have /home/work in your CDPATH, then cd software will get you in /home/work/software.

If you require something closer to the specific question, perhaps setting a directory with symbolic links and putting that directory would be even better. E.g., mkdir ~/.links, then CDPATH=~/.links, and then, inside ~/.links, create a symbolic link mywork to /home/work/software. Then cd mywork should get you there.

0

This is not exactly what you are asking for, but you may want to take a look at Z (works in bash and zsh) which tracks your most used directories, based on 'frecency' and let you jump around.

In your example it would be something like:

z software

and it would probably change the directory to:

 /home/work/software
0

I followed the suggestion here: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html and never looked back. The key to this utility is that "cd" will follow symbolic links to directories, and a shell function which looks something like:

export JJPATH=$HOME/.jjlinks    
function jj {
    cd -P "$JJPATH/$1" 2>/dev/null || echo "No such link: $1"
}

In the directory $HOME/.jjlinks you stash all the symbolic links you like. There are other simple shell functions to make such a link to the deeply nested directory you currently find yourself.

I used "jj", in honor of the author of this suggestion, (plus that's where my right index finger is most of the time), and so:

 jj pj7

immediately changes my directory to "~/projects/sequence/hepatocyte/seq_783/bin/"

-1

I think this utility might be what you are looking for: http://micans.org/apparix/

Your Answer

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 or ask your own question.