giving a short name for frequently opened directory via terminal [duplicate]

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.


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.