I'll write this assuming you don't know much about Ubuntu - please accept my apologies if it's too straightforward.
Absolutely you can. You need to create an alias.
Pick a name for the command you want to alias to the command you want executed. Open a terminal (CtrlAltT) and type it to check it is not currently assigned to something.
So let's say you want to use the command prog
to move to that directory, you can make it temporarily happen by creating an alias for your absolute path to the directory you want. Open a terminal and type
alias prog="cd /home/user/Desktop/Programming/C++"
(obviously you'll need to put in the correct path to your target folder; do note it has to be an absolute path not a relative one).
Then, within that terminal session, every time you type prog
it will execute the cd /home/user/Desktop/Programming/C++
command.
Note that this will only work during that terminal session. To make it permanent, you'll need to edit the .bashrc
file:
You need to be comfortable editing text configuration files.
I’m not personally comfortable using Vi / Vim – but nano is pretty straightforward.
It involves editing .bashrc
which is in your home directory.
This is, I think, pretty safe, even if you're not very familiar with editing such files:
Open a terminal (CtrlAltT)
Go to your home directory with cd ~
Confirm .bashrc
is there with ls -a
Assuming it is, first create a backup copy of it so you can undo it if you mess it up completely:
cp .bashrc .bashrc-bak
(if you cause a problem you can reinstate the original .bashrc
file by typing cp .bashrc-bak .bashrc
)
Now you can edit .bashrc
knowing there is a safe copy:
Type nano .bashrc
(or you can use an alternative text editor if you prefer)
This opens .bashrc
in the text editor.
Whilst you can add the lines anywhere, it makes sense for future editing to find a space where there are some aliases and add yours below the ones there:
alias prog=”cd /home/user/Desktop/Programming/C++”
Then save the file by hitting CtrlO, and exit nano with CtrlX.
If you make a mistake, if you can't undo it, exit nano (CtrlX) without saving and start again.
The change will take effect as soon as you either start a new terminal session, or type . ~/.bashrc
(note the .
at the beginning!).