Every time I wish to move to a directory I use very often, I must type this long directory path:

cd /media/prasanth/01D0F888E7BC91801/github projects

or I must use the gui to get into the folder and open the terminal.

Is it possible to assign this long path to a single name and enter it via the terminal like

cd mygitfiles



So far two great have been given in other answers, I have one more possibility:

ln -s /media/prasanth/01D0F888E7BC91801/github/projects ~/mygitfiles

Will create a symlink to the long path in your home.

Symlinks are like shortcuts that point to another file or directory, and most programs will treat them as normal. you can safely rm the symlink without effecting the path it points to. you can observe where the symlink points to with ls -l.

You can use the symlink as if it was a real directory and do cd ~/mygitfiles.

Note that ~ is simply an alias for your home directory, which might be a sensible place for such a symlink.

Be aware that using this symlink ultimately effects your current working directory.

In the general case I would suggest Nicolas Delvaux, or Eduardo Cola's answer, but using a symlink might be just as - or possibly more useful.


You should use aliases. See help alias.

In a nutshell, you can define an alias by typing:

alias whatever="cd /media/prasanth/01D0F888E7BC91801/github/projects"

Then, typing whatever will move you to the defined folder.

You can put the alias command in your ~/.bashrc to keep it permanently.


It seems like you're looking for cdargs.

It provides bookmarks for the cd command.

You can add a bookmark by executing mark NAME in the directory that is bookmarked. Then you can change to this directory from anywhere using cv NAME with NAME being the name of the bookmark.

  • 1
    Wow. My life just got that much easier. Thank you! – Michael Hoffmann Jan 6 '16 at 7:49

You can store your path in an environment variable. Run:

nano $HOME/.bashrc

Go to the end of the file, create a new line and write:

export mgf="/media/prasanth/01D0F888E7BC91801/github projects"

Hit Ctrl+O and ENTER to save the file. Hit Ctrl+X to exit. Now log out and log in. When youn open a terminal (running bash) you can run cd "$mgf" to change to your directory.

  • 3
    There's no need to logout though. Either run . ~/.bashrc (if in the console or in a terminal) or close / reopen the terminal (if in a terminal). – kos Jan 4 '16 at 15:12
  • 3
    There's no need for the sudo. It's your .bashrc, you should be able to edit it. – Maerlyn Jan 4 '16 at 16:51
  • 1
    Good answer and this can work with subdirectories, like cd $mgf/subdir/. Upvoted – Sergiy Kolodyazhnyy Jan 4 '16 at 19:32
  • Putting this in .bashrc limits its usefulness to only bash shells, and is a waste of resources. There's no need to run this on every subshell invocation in ~/.bashrc. It should be in ~/.profile so it is read by any login shell, as explained at What are the functional differences between .profile .bash_profile and .bashrc - Server Fault – nealmcb Jun 17 '18 at 17:46

You could have a look at autojump. It basically learns as you use cd by building a database of folders you visit and assigning weights to them: the more you visit a folder, the higher it is in the database.

Then, after you cd a few times to a directory (even once suffices):

cd /media/prasanth/01D0F888E7BC91801/github projects

you can jump there by using the j command:

j proj

You can use any part of the directory name as an argument to the j command and it will jump to the first entry that matches, so that's helpful when you don't remember the full path.

It has some other capabilities which are pretty neat such as jump to child (jc). I encourage you to inspect it.

  • I use autojump, and it works well. The best thing is that it learns from your use. I didn't know about jc, so that's something for me to look at. – Paddy Landau Jan 12 '16 at 11:08

Bash has a handy little misfeature called CDPATH. When cd foo looks for a relative path, it looks in the current directory by default. By setting CDPATH to a colon-separated list of path prefixes, we can go to that target instead if no match was found. This works similarly to the PATH variable when looking for executable files.

In your case, you could export CDPATH=.:/media/prasanth/01D0F888E7BC91801/github/ in your ~/.bashrc, and then execute cd projects/foo from anywhere to get to /media/prasanth/01D0F888E7BC91801/github/projects/foo.

However, this will not work if your current directory contains a matching entry, so this can have some confusing error modes. There are some people that swear by this methods, I myself rather prefer symlinks in the home directory as suggested by Paul Grove.


I would type

cd /media/prasanth/01D0F888E7BC91801/github projects #demo-proj

the first time I run that command. The content after # is a comment.

Then to call it, I would CtrlR and type in de (a convenient substring of demo-proj), till the previous command comes up.

(reverse-i-search)`de': cd /media/prasanth/01D0F888E7BC91801/github projects #demo-proj

I can hit CtrlR again for even-earlier uses.

This has no need to set/replace permanent aliases. I also do this for long commands or even netstat -tulpn which I find cryptic.

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