Back to all posts

Alias Your Commands in Bash on WSL Ubuntu

How I create a Bash alias in my .bashrc file on WSL Ubuntu, using NVDA and Visual Studio Code.

Watch the video

Create a short command with an alias

I usually work in a Bash shell using WSL Ubuntu on Windows. I like to alias commands so I am not always typing the full command, especially when it is long or repetitive.

For this example, I add an alias to my ~/.bashrc file that maps the letter c to the clear command. I am using NVDA on a Windows 11 machine.

Open Ubuntu and confirm your location

You can open the Ubuntu app directly. From Git Bash, you can run wsl to open your default WSL distribution. To open Ubuntu specifically, run:

wsl -d Ubuntu

Once I am inside the Bash shell, I run pwd. NVDA reads /home/codingblindtech, confirming that I am in my home folder.

Open .bashrc in Visual Studio Code

The file is named .bashrc, all lowercase with no spaces. I open it with:

code ~/.bashrc

The tilde is typed with Shift and the key above Tab, to the left of the 1. In this path, the tilde represents my home folder.

I have Visual Studio Code installed on Windows. The first time I run code from inside WSL, it installs the VS Code server on the Linux side and uses the Visual Studio Code client on Windows.

Add the alias

Move to a blank line at the end of the file or in your personal aliases section. I add a comment first so I know what the alias is for:

# Alias Clear Command

On the next line, add the alias itself:

alias c='clear'

I have NVDA read both lines back to confirm they are correct, then press Ctrl+S to save.

Reload .bashrc

I switch back to the terminal with Alt+Tab and try the alias. When I type c and press Enter, NVDA reads c: command not found because the current shell has not loaded the change.

There are two ways to handle that. You can close the terminal and open a new one, or you can reload the file in the current shell with:

source ~/.bashrc

The first time I run the command, I mistype the path as ~./bashrc, and Bash reports:

-bash: ~./bashrc: No such file or directory

I press the Up arrow to bring the command back, press End to move to the end of the line, and correct it to source ~/.bashrc.

After the file reloads, I type c and press Enter again. NVDA does not give me any spoken feedback, but when I review the terminal, the previous output is cleared from view. That is exactly what I wanted: c now runs clear.