When navigating through the Linux terminal, you'll often find yourself repeating many commands, where more often than not these commands will be particularly long. For example, let's say I have nested directories and I constantly need to cd into the most nested directory, like below:
It would be a bit of a pain to type the following constantly:
Linux, however, allows you to create Aliases, which are essentially user-defined shortcuts for any type of command that you can input. In the case of above, I could create the following alias:
alias cdC="cd ~/dirA/dirB/dirC"
Now, whenever I type cdC, I would cd into the nested directory dirC, which uses substantially less characters for the same result!
Note that using the alias command only creates aliases for the current terminal session. This means that upon opening a new terminal session, all your aliases would be reset to default. If you would like to create permanent aliases, you must modify your bash.rc file.
You can then place your alias shortcut anywhere within this .bashrc file, and it'll save your aliases for all future terminal sessions.
After editing your .bashrc file, you can open another terminal session to use your updated aliases, or you can input the command:
The above command will update your aliases for the current terminal session.
Additionally, if you want to remove any aliases you created via the command line, you can use the unalias command as follows:
unalias *alias name*
Note that unalias leaves any aliases created in your .bashrc file untouched.
Please sign in to leave a comment.