July 17, 2017
Create a Bash alias for a Terminal command
Do you find yourself frequently typing out the same command in Terminal? One simple way to make your workflow more efficient is to create a Bash alias.
Do you find yourself frequently typing out the same command in Terminal? One simple way to make your workflow more efficient is to create a Bash alias.
Follow these simple steps
Open your terminal emulator of choice. I use the macOS default Terminal.
Type in the command bash sudo nano .bash_profile
then press Enter. This command will open .bash_profile in the Nano text editor. You may be prompted for your password.
Once .bash_profile is open, type in alias
followed by the alias name you would like to use. Now, add an =
sign and place the desired command between two '
characters. In the example below, I created an alias called youraliasname
and assigned it cd cats/tabbies
.
Press CTRL+X to exit Nano and save your changes to .bash_profile. If everything looks right, press Y.
Nano will ask you to confirm the file name to write the changes to. Press Enter to overwrite the previous version of .bash_profile.
Close and reopen Terminal (or your chosen emulator) to use your new alias. Test out your new alias by typing the alias name and pressing Enter.
You're all set! 🚀