How to Make Command Aliases in Bash

Search for a command to run...

No comments yet. Be the first to comment.
FYI: This is experimental and may not work on your system.

Hey all! I made this guide after getting Starship successfully working on Bash, but zsh would refuse to accept the init script. Step 0 - Set a custom password This step is not required if you've already set a custom password for your Crostini contain...

If you've ever coded for an Arduino, you're probably familiar with the Arduino IDE. Is your IDE just not uploading your sketch? Are you getting an error such as this? If so, the fix is quite simple. First, locate the Tools section on the top bar of ...

GitHub CLI is a wonderful new tool released by GitHub in an effort to bring GitHub to the terminal. In this tutorial, I will be showing you how to setup, install and use some basic features of GitHub CLI. Installation Because of the amount of install...

Hey all! This is a quick one, but I use command aliases all the time and they make my life so much easier when I'm in the terminal. Let's get started!
The .bashrc file is short for "bash run commands". It can be located in your home directory at ~/.bashrc. It contains a few preset configurations already. For this tutorial, I will be using Nano as my primary text editor. You can install it on Ubuntu and Debian using the command listed below.
sudo apt install nano -y
We can now cd to our home directory and run the listed below command to open our .bashrc file.
nano .bashrc
I recommend putting aliases at the end of your .bashrc file. To get to the end of a file in Nano, press Ctrl+V repeatedly until you reach the end. Let's make a command alias for asciinema. asciinema is a terminal recorder that I use often to capture command errors and demonstrate my Python scripts. I will call this alias asc, as the provided command, asciinema is quite lengthy. I will write the below listed code and explain it.
# Command aliases
alias asc='asciinema'
alias signals to Bash that the next word is a command alias. asc is the name of the alias. The = means the rest of the line defines the alias. 'asciinema' defines the action that the alias carries out.
Now that we are done, save and close the file in Nano by typing Ctrl+X, y, and Enter.
Now let's see if our alias works. First, close your current bash session and open a new one. This reloads the .bashrc file with the new configuration.
onx@penguin:~$ asc rec
asciinema: recording asciicast to /tmp/tmpaliz0fko-ascii.cast
asciinema: press <ctrl-d> or type "exit" when you're done
onx@penguin:~$ echo hello world!
hello world!
onx@penguin:~$ echo awesome! it works!
awesome! it works!
onx@penguin:~$ exit
exit
asciinema: recording finished
asciinema: press <enter> to upload to asciinema.org, <ctrl-c> to save locally
View the recording at:
https://asciinema.org/a/lPYgTBguPVz4g27KnuXO5pLTB
You can go view the recording for yourself if you like :)
Congratulations! You've learned how to make command aliases in Bash! Have a great day everyone and let me know what I should write about next in the comments!