“TeckMile.com – Elevating Your Skills and Creativity, One Project at a Time.”

Simplified Guide to Bash Aliases

What is an Alias?

In Linux, an alias is a custom shortcut or alternate name for a command, making it easier to execute frequently used commands or complex ones with fewer keystrokes.

To create an alias, open your terminal and follow these steps:

Step 1: Open the ~/.bash_aliases File

nano ~/.bash_aliases

Step 2: Define Your Alias

In the ~/.bash_aliases file, define your alias. For example:

alias cds="cd ~/Scripts"

Replace "cd ~/Scripts" with your desired command.

Step 3: Check if ~/.bashrc Recognizes ~/.bash_aliases

By default, some Linux distributions already include code in ~/.bashrc to load ~/.bash_aliases. To check if your ~/.bashrc includes this code, open it:

nano ~/.bashrc

Look for a line like:

if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi

If you find it, your ~/.bashrc is configured to load ~/.bash_aliases, and you can skip the next step.

Step 4: Add Code to ~/.bashrc (if not already present)

If you didn’t find the code in the previous step, add it to the end of your ~/.bashrc file:

if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi

Step 5: Refresh Bash

To apply the changes without restarting your terminal, run:

source ~/.bashrc

Now, your newly created alias is ready to use:

cds

Replace cds with the alias you created.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *